public static void Set <TEntity>(this Abstractions.IDistributedCache cache, string key, TEntity entity) { var options = new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(20)); var binary = entity.Serialize(); cache.Set(key, binary, options); }
public static Task SetAsync <TEntity>(this Abstractions.IDistributedCache cache, string key, TEntity entity, int ttl) { var options = new DistributedCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromSeconds(ttl)); var binary = entity.Serialize(); return(cache.SetAsync(key, binary, options)); }
public static TEntity Get <TEntity>(this Abstractions.IDistributedCache cache, string key) { TEntity result = default; var binary = cache.Get(key); if (binary != null) { result = binary.Deserialize <TEntity>(); } return(result); }
public static async Task <TEntity> GetAsync <TEntity>(this Abstractions.IDistributedCache cache, string key) { TEntity result = default; var binary = await cache.GetAsync(key); if (binary != null) { result = binary.Deserialize <TEntity>(); } return(result); }
public static TEntity GetOrCreate <TEntity>(this Abstractions.IDistributedCache cache, string key, Func <TEntity> predicate) { TEntity entity = cache.Get <TEntity>(key); if (entity != null) { return(entity); } entity = predicate(); cache.Set(key, entity); return(entity); }
public static async Task <TEntity> GetOrCreateAsync <TEntity>(this Abstractions.IDistributedCache cache, string key, Func <Task <TEntity> > predicate, int ttl) { TEntity entity = await cache.GetAsync <TEntity>(key); if (entity != null) { return(entity); } entity = await predicate(); await cache.SetAsync(key, entity, ttl); return(entity); }
/// <summary> /// Initializes a new instance of the <see cref="NetStandardIDistributedCacheStringProvider"/> class. /// </summary> /// <param name="iDistributedCache">An IDistributedCache implementation with which to store cached items.</param> public NetStandardIDistributedCacheStringProvider(Microsoft.Extensions.Caching.Distributed.IDistributedCache iDistributedCache) : base(iDistributedCache) { }
public AlarmStatusController(IAlarmStatusAppService alarmStatusAppService, Microsoft.Extensions.Caching.Distributed.IDistributedCache cache) { _alarmStatusAppService = alarmStatusAppService; _cache = cache; }