public void All() { var cache = new IsolatedKeyValueCache <string, string>( new[] { new CacheIsolateByLocale() }, new MemoryCache <IsolatedCacheKey <string>, string>()); // Set LocaleUtils.SetThreadLanguage("zh-CN"); cache.Put("Key", "ValueForCN", TimeSpan.FromSeconds(5)); LocaleUtils.SetThreadLanguage("en-US"); cache.Put("Key", "ValueForUS", TimeSpan.FromSeconds(5)); // Get LocaleUtils.SetThreadLanguage("zh-CN"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForCN"); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForUS"); // Remove LocaleUtils.SetThreadLanguage("zh-CN"); cache.Remove("Key"); Assert.Equals(cache.GetOrDefault("Key"), null); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForUS"); cache.Remove("Key"); Assert.Equals(cache.GetOrDefault("Key"), null); }
/// <summary> /// Initialize<br/> /// 初始化<br/> /// </summary> public LocalPathManager() { var configManager = Application.Ioc.Resolve <WebsiteConfigManager>(); TemplatePathCacheTime = TimeSpan.FromSeconds( configManager.WebsiteConfig.Extra.GetOrDefault(ExtraConfigKeys.TemplatePathCacheTime, 2)); ResourcePathCacheTime = TimeSpan.FromSeconds( configManager.WebsiteConfig.Extra.GetOrDefault(ExtraConfigKeys.ResourcePathCacheTime, 2)); // Path may different between servers, shouldn't use ICacheFactory here TemplatePathCache = new IsolatedKeyValueCache <string, string>( new[] { Application.Ioc.Resolve <ICacheIsolationPolicy>(serviceKey: "Device") }, new MemoryCache <IsolatedCacheKey <string>, string>()); ResourcePathCache = new IsolatedKeyValueCache <string, string>( new[] { Application.Ioc.Resolve <ICacheIsolationPolicy>(serviceKey: "Device") }, new MemoryCache <IsolatedCacheKey <string>, string>()); }