public void Test_ThreadSafeObjectCache() { var cache = new ThreadSafeObjectCache <string>(new MemoryCache("ThreadSafeObjectCache_Tests")); var cacheCallCount = 0; var aValue = cache.Get("A", () => { ++cacheCallCount; return("A-value-1"); }); aValue.ShouldBe("A-value-1"); cacheCallCount.ShouldBe(1); var bValue = cache.Get("B", () => { ++cacheCallCount; return("B-value-1"); }); bValue.ShouldBe("B-value-1"); cacheCallCount.ShouldBe(2); aValue = cache.Get("A", () => { ++cacheCallCount; return("A-value-2"); }); aValue.ShouldBe("A-value-1"); cacheCallCount.ShouldBe(2); }
public void Test_ThreadSafeObjectCache() { var cache = new ThreadSafeObjectCache<string>(new MemoryCache("ThreadSafeObjectCache_Tests")); var cacheCallCount = 0; var aValue = cache.Get("A", () => { ++cacheCallCount; return "A-value-1"; }); aValue.ShouldBe("A-value-1"); cacheCallCount.ShouldBe(1); var bValue = cache.Get("B", () => { ++cacheCallCount; return "B-value-1"; }); bValue.ShouldBe("B-value-1"); cacheCallCount.ShouldBe(2); aValue = cache.Get("A", () => { ++cacheCallCount; return "A-value-2"; }); aValue.ShouldBe("A-value-1"); cacheCallCount.ShouldBe(2); }
public SettingManager(ISettingRepository settingRepository, ISettingDefinitionManager settingDefinitionManager) { _settingRepository = settingRepository; _settingDefinitionManager = settingDefinitionManager; _applicationSettings = new Lazy <Dictionary <string, Setting> >(GetApplicationSettingsFromDatabase, true); _tenantSettingCache = new ThreadSafeObjectCache <Dictionary <string, Setting> >(new MemoryCache(GetType().Name + "_TenantSettings"), TimeSpan.FromMinutes(60)); //TODO: Get constant from somewhere else. _userSettingCache = new ThreadSafeObjectCache <Dictionary <string, Setting> >(new MemoryCache(GetType().Name + "_UserSettings"), TimeSpan.FromMinutes(30)); //TODO: Get constant from somewhere else. }
public SettingManager(ISettingDefinitionManager settingDefinitionManager) { _settingDefinitionManager = settingDefinitionManager; Session = NullAbpSession.Instance; SettingStore = NullSettingStore.Instance; //Should be constructor injection? For that, ISettingStore must be registered! _applicationSettings = new Lazy <Dictionary <string, SettingInfo> >(GetApplicationSettingsFromDatabase, true); _tenantSettingCache = new ThreadSafeObjectCache <Dictionary <string, SettingInfo> >(new MemoryCache(GetType().FullName + ".TenantSettings"), TimeSpan.FromMinutes(60)); //TODO: Get constant from somewhere else. _userSettingCache = new ThreadSafeObjectCache <Dictionary <string, SettingInfo> >(new MemoryCache(GetType().FullName + ".UserSettings"), TimeSpan.FromMinutes(20)); //TODO: Get constant from somewhere else. }
/// <summary> /// This method is called by ASP.NET system on web application's startup. /// </summary> protected virtual void Application_Start(object sender, EventArgs e) { AbpBootstrapper.IocManager.RegisterIfNot <IAssemblyFinder, WebAssemblyFinder>(); var cache = new ThreadSafeObjectCache <object>(new MemoryCache("_AbpWebApplicationCache"), TimeSpan.FromHours(3)); //AbpBootstrapper.IocManager.RegisterIfNot<ThreadSafeObjectCache<string>>(); AbpBootstrapper.IocManager.IocContainer.Register( Component.For <ThreadSafeObjectCache <object> >().Named("_AbpBootstrapper").Instance(cache).LifestyleTransient()); AbpBootstrapper.Initialize(); //为了能够使用AntiForgeryToken,该处配置是必须的 AntiForgeryConfig.UniqueClaimTypeIdentifier = AbpClaimTypes.UserIdClaimType; }
/// <summary> /// Initializes a new instance of the <see cref="Abp.Web.Localization.LocalizationScriptManager"/> class. /// </summary> /// <param name="localizationManager">Localization manager.</param> public LocalizationScriptManager(ILocalizationManager localizationManager) { _localizationManager = localizationManager; _cache = new ThreadSafeObjectCache <string>(new MemoryCache("__LocalizationScriptManager"), TimeSpan.FromDays(1)); }
public UserRoleManager(IUserRoleRepository userRoleRepository) { _userRoleRepository = userRoleRepository; _userInfoCache = new ThreadSafeObjectCache <UserRoleInfo>(new MemoryCache(GetType().Name), TimeSpan.FromMinutes(30)); //TODO: Get constant from somewhere else. }
/// <summary> /// Initializes a new instance of the <see cref="Abp.Web.Localization.LocalizationScriptManager"/> class. /// </summary> /// <param name="localizationManager">Localization manager.</param> public LocalizationScriptManager(ILocalizationManager localizationManager) { _localizationManager = localizationManager; _cache = new ThreadSafeObjectCache<string>(new MemoryCache("__LocalizationScriptManager"), TimeSpan.FromDays(1)); }
public UserRoleManager(IUserRoleRepository userRoleRepository) { _userRoleRepository = userRoleRepository; _userInfoCache = new ThreadSafeObjectCache<UserRoleInfo>(new MemoryCache(GetType().Name), TimeSpan.FromMinutes(30)); //TODO: Get constant from somewhere else. }