public PartialViewResult MenuCategoryEvents() { //without interface use : HttpContext.Cache.Add("Some value"); ICache abstractCache = new AbstractCache(); List <GamingEvent> randomEvents; List <CategoryEvent> gameEventsCategories; if (abstractCache.IsSet(ConfigurationManager.AppSettings["RandomEventOffer"])) { randomEvents = abstractCache.Get(ConfigurationManager.AppSettings["RandomEventOffer"]) as List <GamingEvent>; } else { randomEvents = context.GamingEvents.OrderByDescending(g => Guid.NewGuid()).Take(3).ToList(); abstractCache.Set(ConfigurationManager.AppSettings["RandomEventOffer"], randomEvents, 60); } if (abstractCache.IsSet(ConfigurationManager.AppSettings["GameEventsCategories"])) { gameEventsCategories = abstractCache.Get(ConfigurationManager.AppSettings["GameEventsCategories"]) as List <CategoryEvent>; } else { gameEventsCategories = context.CategoryEvents.ToList(); abstractCache.Set(ConfigurationManager.AppSettings["GameEventsCategories"], gameEventsCategories, 1440); } var vm = new GameEventCategoryMenuViewModel() { GamingEvents = randomEvents, CategoryEvents = gameEventsCategories }; return(PartialView("_MenuCategoryGameEvents", vm)); }
/// <summary> /// Registers specified cache as singleton implementation for <see cref="ICache"/>, /// <see cref="IAsyncCache"/>, <see cref="IDistributedCache"/>. /// </summary> /// <typeparam name="TCache">Cache type.</typeparam> /// <typeparam name="TSettings">Cache settings type.</typeparam> /// <param name="services">Services collection.</param> /// <param name="cache">The cache that should be registered.</param> /// <returns>Modified services collection.</returns> public static IServiceCollection AddKVLiteCache <TCache, TSettings>(this IServiceCollection services, AbstractCache <TCache, TSettings> cache) where TCache : AbstractCache <TCache, TSettings> where TSettings : AbstractCacheSettings <TSettings> { if (cache != null) { services.AddSingleton <ICache>(cache); services.AddSingleton <ICache <TSettings> >(cache); services.AddSingleton <IAsyncCache>(cache); services.AddSingleton <IAsyncCache <TSettings> >(cache); services.AddSingleton <IDistributedCache>(cache); } return(services); }
void Awake() { cache = GetComponentInChildren <AbstractCache <T> >(); _itemPosition = -1; }