Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharpNotesForProfessionals.pdf
Скачиваний:
57
Добавлен:
20.05.2023
Размер:
6.12 Mб
Скачать

Chapter 130: Caching

Section 130.1: MemoryCache

//Get instance of cache

using System.Runtime.Caching;

var cache = MemoryCache.Default;

//Check if cache contains an item with cache.Contains("CacheKey");

//get item from cache

var item = cache.Get("CacheKey");

//get item from cache or add item if not existing

object list = MemoryCache.Default.AddOrGetExisting("CacheKey", "object to be stored", DateTime.Now.AddHours(12));

//note if item not existing the item is added by this method //but the method returns null

GoalKicker.com – C# Notes for Professionals

653