private async Task <T> GetFromCache <T>(string key) where T : class { T cacheObj = null; var byteArray = await _cache.GetAsync(key); if (byteArray != null) { cacheObj = await DistributedCacheSerializer.Deserialize <T>(byteArray).ConfigureAwait(false); } return(cacheObj); }
private async Task SetToCache <T>(string path, string identifier, T cacheObj) where T : class { byte[] arr = DistributedCacheSerializer.Serialize(cacheObj); (int slidingExpirationInMinutes, int absoluteExpirationInMinutes) = GetCacheSettings(path); var cacheOptions = new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(slidingExpirationInMinutes), AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(absoluteExpirationInMinutes) }; string key = GetCacheKey(path, identifier); await _cache.SetAsync(key, arr, cacheOptions).ConfigureAwait(false); }