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 <string> GetAsync(string str) { var method = str.ToLower(); switch (method) { case "get": var res = await _provider.GetAsync("demo", async() => await Task.FromResult("456"), TimeSpan.FromMinutes(1)); return($"cached value : {res}"); case "set": await _provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1)); return("seted"); case "remove": await _provider.RemoveAsync("demo"); return("removed"); case "getcount": var count = _provider.GetCount(); return($"{count}"); default: return("default"); } }
/// <summary> /// Processes the evict async. /// </summary> /// <returns>The evict async.</returns> /// <param name="context">Context.</param> /// <param name="isBefore">If set to <c>true</c> is before.</param> private async Task ProcessEvictAsync(AspectContext context, bool isBefore) { if (GetMethodAttributes(context.ServiceMethod).FirstOrDefault(x => x.GetType() == typeof(EasyCachingEvictAttribute)) is EasyCachingEvictAttribute attribute && attribute.IsBefore == isBefore) { try { if (attribute.IsAll) { //If is all , clear all cached items which cachekey start with the prefix. var cachePrefix = KeyGenerator.GetCacheKeyPrefix(context.ServiceMethod, attribute.CacheKeyPrefix); await _cacheProvider.RemoveByPrefixAsync(cachePrefix); } else { //If not all , just remove the cached item by its cachekey. var cacheKey = KeyGenerator.GetCacheKey(context.ServiceMethod, context.Parameters, attribute.CacheKeyPrefix); await _cacheProvider.RemoveAsync(cacheKey); } } catch (Exception ex) { if (!attribute.IsHightAvailability) { throw; } else { Logger?.LogError(new EventId(), ex, $"Cache provider \"{_cacheProvider.Name}\" remove error."); } } } }
/// <summary> /// Removes the specified cacheKey async. /// </summary> /// <returns>The async.</returns> /// <param name="cacheKey">Cache key.</param> public async Task RemoveAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); await _localCachingProvider.RemoveAsync(cacheKey); await _distributedCachingProvider.RemoveAsync(cacheKey); }
public async void RemovePresignedUrlCache(string bucketName, string objectName) { if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } if (string.IsNullOrEmpty(objectName)) { throw new ArgumentNullException(nameof(objectName)); } if (Options.IsEnableCache) { string key = Encrypt.MD5($"{bucketName}_{objectName}_{PresignedObjectType.Put.ToString().ToUpper()}"); await _cache.RemoveAsync(key); key = Encrypt.MD5($"{bucketName}_{objectName}_{PresignedObjectType.Get.ToString().ToUpper()}"); await _cache.RemoveAsync(key); } }
public Task RemoveAsync(string key, CancellationToken token = default) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _expirations.TryRemove(key, out TimeSpan _); return(_easyCachingProvider.RemoveAsync(key)); }
/// <summary> /// Removes the specified cacheKey async. /// </summary> /// <returns>The async.</returns> /// <param name="cacheKey">Cache key.</param> public async Task RemoveAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); //distributed cache at first await _distributedCache.RemoveAsync(cacheKey); await _localCache.RemoveAsync(cacheKey); //send message to bus await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); }
/// <summary> /// Removes the specified cacheKey async. /// </summary> /// <returns>The async.</returns> /// <param name="cacheKey">Cache key.</param> public async Task RemoveAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); try { // distributed cache at first await _distributedCache.RemoveAsync(cacheKey); } catch (Exception ex) { _logger?.LogError(ex, "remove cache key [{0}] error", cacheKey); } await _localCache.RemoveAsync(cacheKey); // send message to bus await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); }
/// <summary> /// 清除缓存数据(异步) /// </summary> public async Task ClearCacheDataAsync() { await _provider.RemoveAsync(_cacheKey); }
protected virtual async Task LPushAsync_And_LPopAsync_Should_Succeed() { var cacheKey = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; var res = await _provider.LPushAsync(cacheKey, new List <string> { "p1", "p2" }); Assert.Equal(2, res); var val = await _provider.LPopAsync <string>(cacheKey); Assert.Equal("p2", val); await _baseProvider.RemoveAsync(cacheKey); }
public async Task Update <T>(string key, T data, TimeSpan?expiration = null) { await _provider.RemoveAsync(key); await _provider.SetAsync(key, data, expiration ?? TimeSpan.FromMinutes(10)); }
/// <summary> /// Removes cache with specified key /// </summary> public async Task RemoveAsync(string key) { await _provider.RemoveAsync(key); }
public async Task Remove_Cached_Value_Async_Should_Throw_ArgumentNullException_When_CacheKey_IsNullOrWhiteSpace(string cacheKey) { await Assert.ThrowsAsync <ArgumentNullException>(async() => await _provider.RemoveAsync(cacheKey)); }
public async Task ClearCacheAsync() => await _cache.RemoveAsync(Constants.RedisKey.Settings);
public Task Remove(string cacheKey) => _provider.RemoveAsync(cacheKey);
/// <summary> /// 刷新 AccessToken。清除缓存,重新获取 /// </summary> /// <returns></returns> public async Task <string> RefreshAccessToken() { await _provider.RemoveAsync(CacheKey); return(await GetAccessToken()); }
public Task RemoveAsync(string key) { return(_provider.RemoveAsync(key)); }
/// <summary> /// Removes the specified cacheKey async. /// </summary> /// <param name="cacheKey">Cache key.</param> /// <param name="cancellationToken">cancellationToken</param> /// <returns>Task</returns> public Task RemoveAsync(string cacheKey, CancellationToken cancellationToken = default) { return(_easyCachingProvider.RemoveAsync(cacheKey)); }
public async Task <ApiResult <bool> > DeleteCart(string key) { await cachingProvider.RemoveAsync(key); return(new ApiSuccessResult <bool>()); }
public async Task Clear(string cacheKey) { await _cache.RemoveAsync(CreateCacheKey(cacheKey)); }
public async Task <bool> DeleteBasketAsync(string id) { await easyCachingProvider.RemoveAsync("Basket_" + id); return(true); }