public static string ReadLocalCacheFile(this string filePath, Encoding objEncoding = null) { if (string.IsNullOrWhiteSpace(filePath)) { return(""); } string childKey = filePath.MD5Encrypt(); string fromCache = CacheHelper.GetFromCache <string>("LocalFile", childKey); if (fromCache == null) { if (CacheHelper.GetFromCache("LocalFile", childKey + "NoFile") != null) { return(""); } ReaderWriterLockSlim slim = objFileCacheWriterLockSlimHelper.CreateLock(childKey); slim.EnterWriteLock(); try { fromCache = CacheHelper.GetFromCache <string>("LocalFile", childKey); if (fromCache == null) { if (CacheHelper.GetFromCache("LocalFile", childKey + "NoFile") != null) { return(""); } if (!System.IO.File.Exists(filePath)) { true.AddToFileCache("LocalFile", childKey + "NoFile", filePath); return(""); } if (objEncoding == null) { fromCache = System.IO.File.ReadAllText(filePath); } else { fromCache = System.IO.File.ReadAllText(filePath, objEncoding); } fromCache.AddToFileCache("LocalFile", childKey, filePath); } return(fromCache); } finally { slim.ExitWriteLock(); } } return(fromCache); }
private static System.Configuration.Configuration GetConfigurationCode(string configCode) { if (string.IsNullOrWhiteSpace(configCode)) { return(null); } System.Configuration.Configuration fromCache = CacheHelper.GetFromCache <System.Configuration.Configuration>(WTF.Framework.CacheType.Framework.ToString(), configCode); if (fromCache == null) { if (CacheHelper.GetFromCache(WTF.Framework.CacheType.Framework.ToString(), configCode + "NoFile") != null) { return(null); } ReaderWriterLockSlim slim = objConfigWriterLockSlimHelper.CreateLock(configCode); slim.EnterWriteLock(); try { fromCache = CacheHelper.GetFromCache <System.Configuration.Configuration>(WTF.Framework.CacheType.Framework.ToString(), configCode); if (fromCache == null) { if (CacheHelper.GetFromCache(WTF.Framework.CacheType.Framework.ToString(), configCode + "NoFile") != null) { return(null); } string configPath = GetConfigPath(configCode); if (!File.Exists(configPath)) { true.AddToFileCache(WTF.Framework.CacheType.Framework.ToString(), configCode + "NoFile", configPath); return(null); } ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath }; fromCache = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); fromCache.AddToFileCache(WTF.Framework.CacheType.Framework.ToString(), configCode, configPath); } return(fromCache); } finally { slim.ExitWriteLock(); } } return(fromCache); }