public async Task SetAsync_And_ExistsAsync_Should_Succeed() { var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; await hybridCaching_1.SetAsync(cacheKey, "val", TimeSpan.FromSeconds(30)); var res = await hybridCaching_1.ExistsAsync(cacheKey); Assert.True(res); }
public async Task <string> GetAsync(string str) { var method = str.ToLower(); switch (method) { case "get": var res = await _provider.GetAsync("demo", async() => await Task.FromResult("3-456"), TimeSpan.FromHours(1)); return($"cached value : {res}"); case "set": await _provider.SetAsync("demo", "3-123", TimeSpan.FromHours(1)); return("seted"); case "remove": await _provider.RemoveAsync("demo"); return("removed"); default: return("default"); } }
public async Task <string> GetAsync(int type = 1) { if (type == 1) { await _provider.RemoveAsync("demo"); return("removed"); } else if (type == 2) { await _provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1)); return("seted"); } else if (type == 3) { var res = await _provider.GetAsync("demo", async() => await Task.FromResult("456"), TimeSpan.FromMinutes(1)); return($"cached value : {res}"); } else { return("error"); } }
public async Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeToLive) { if (response == null) { return; } await _hybridCachingProvider.SetAsync(cacheKey, response, timeToLive); }
public Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = default) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var expiration = GetEasyCacheExpiration(options); _expirations.TryAdd(key, expiration); return(_hybridCachingProvider.SetAsync(key, value, expiration)); }