From 18087277dce63c834a067f98cc2c1d6a2043af5e Mon Sep 17 00:00:00 2001 From: OneDNN Date: Mon, 22 Nov 2021 00:57:34 +0700 Subject: [PATCH] Fix outputcache wrong datetime format cultureinfo --- .../Services/ModuleCache/FileProvider.cs | 2 +- .../OutputCache/Providers/FileProvider.cs | 21 +++++++++++++++---- .../Providers/FileResponseFilter.cs | 5 +++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/DNN Platform/Library/Services/ModuleCache/FileProvider.cs b/DNN Platform/Library/Services/ModuleCache/FileProvider.cs index 537a703ed43..453ac97a411 100644 --- a/DNN Platform/Library/Services/ModuleCache/FileProvider.cs +++ b/DNN Platform/Library/Services/ModuleCache/FileProvider.cs @@ -207,7 +207,7 @@ private static string GetCacheFolder(int portalId) if (!string.IsNullOrEmpty(homeDirectoryMapPath)) { - cacheFolder = string.Concat(homeDirectoryMapPath, "Cache\\Pages\\"); + cacheFolder = string.Concat(homeDirectoryMapPath, "Cache\\Modules\\"); if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); diff --git a/DNN Platform/Library/Services/OutputCache/Providers/FileProvider.cs b/DNN Platform/Library/Services/OutputCache/Providers/FileProvider.cs index 7663781a9b7..4bf1019ec35 100644 --- a/DNN Platform/Library/Services/OutputCache/Providers/FileProvider.cs +++ b/DNN Platform/Library/Services/OutputCache/Providers/FileProvider.cs @@ -5,7 +5,8 @@ namespace DotNetNuke.Services.OutputCache.Providers { using System; - using System.Collections.Generic; + using System.Collections.Generic; + using System.Globalization; using System.IO; using System.Text; using System.Web; @@ -170,8 +171,15 @@ public override void SetOutput(int tabId, string cacheKey, TimeSpan duration, by } using (var oWrite = File.CreateText(attribFile)) - { - oWrite.WriteLine(DateTime.UtcNow.Add(duration).ToString()); + { + var currentCulture = CultureInfo.CurrentCulture.DateTimeFormat; + var currentCultureX = CultureInfo.DefaultThreadCurrentCulture.DateTimeFormat; + + var datetimeUtc = DateTime.UtcNow.Add(duration).ToString(CultureInfo.InvariantCulture); + var datetime1 = DateTime.UtcNow.Add(duration).ToString(); + var datetime2 = DateTime.UtcNow.Add(duration).ToString(); + + oWrite.WriteLine(DateTime.UtcNow.Add(duration).ToString(CultureInfo.InvariantCulture)); oWrite.Close(); } } @@ -192,7 +200,12 @@ public override bool StreamOutput(int tabId, string cacheKey, HttpContext contex bool foundFile = false; try { - string attribFile = GetAttribFileName(tabId, cacheKey); + string attribFile = GetAttribFileName(tabId, cacheKey); + if (!File.Exists(attribFile)) + { + return false; + } + string captureFile = GetCachedOutputFileName(tabId, cacheKey); StreamReader oRead = File.OpenText(attribFile); DateTime expires = Convert.ToDateTime(oRead.ReadLine()); diff --git a/DNN Platform/Library/Services/OutputCache/Providers/FileResponseFilter.cs b/DNN Platform/Library/Services/OutputCache/Providers/FileResponseFilter.cs index 179a8063afc..98bf1694510 100644 --- a/DNN Platform/Library/Services/OutputCache/Providers/FileResponseFilter.cs +++ b/DNN Platform/Library/Services/OutputCache/Providers/FileResponseFilter.cs @@ -4,7 +4,8 @@ namespace DotNetNuke.Services.OutputCache.Providers { - using System; + using System; + using System.Globalization; using System.IO; using DotNetNuke.Common.Utilities; @@ -102,7 +103,7 @@ public override byte[] StopFiltering(int itemId, bool deleteData) File.Move(this.CachedOutputTempFileName, this.CachedOutputFileName); StreamWriter oWrite = File.CreateText(this.CachedOutputAttribFileName); - oWrite.WriteLine(this._cacheExpiration.ToString()); + oWrite.WriteLine(this._cacheExpiration.ToString(CultureInfo.InvariantCulture)); oWrite.Close(); }