/// <summary> /// Processes the evict. /// </summary> /// <param name="invocation">Invocation.</param> /// <param name="isBefore">If set to <c>true</c> is before.</param> private void ProcessEvict(IInvocation invocation, bool isBefore) { var serviceMethod = invocation.Method ?? invocation.MethodInvocationTarget; if (GetMethodAttributes(serviceMethod).FirstOrDefault(x => typeof(EasyCachingEvictAttribute).IsAssignableFrom(x.GetType())) is EasyCachingEvictAttribute attribute && attribute.IsBefore == isBefore) { try { if (attribute.IsAll) { //If is all , clear all cached items which cachekey start with the prefix. var cacheKeyPrefix = _keyGenerator.GetCacheKeyPrefix(serviceMethod, attribute.CacheKeyPrefix); if (attribute.IsHybridProvider) { _hybridCachingProvider.RemoveByPrefix(cacheKeyPrefix); } else { var _cacheProvider = _cacheProviderFactory.GetCachingProvider(attribute.CacheProviderName ?? _options.Value.CacheProviderName); _cacheProvider.RemoveByPrefix(cacheKeyPrefix); } } else { //If not all , just remove the cached item by its cachekey. var cacheKey = string.IsNullOrEmpty(attribute.CacheKey) ? _keyGenerator.GetCacheKey(serviceMethod, invocation.Arguments, attribute.CacheKeyPrefix) : attribute.CacheKey ; if (attribute.IsHybridProvider) { _hybridCachingProvider.Remove(cacheKey); } else { var _cacheProvider = _cacheProviderFactory.GetCachingProvider(attribute.CacheProviderName ?? _options.Value.CacheProviderName); _cacheProvider.Remove(cacheKey); } } } catch (Exception ex) { if (!attribute.IsHighAvailability) { throw; } else { _logger?.LogError(new EventId(), ex, $"Cache provider remove error."); } } } }
public void ClearRegion(string region) { if (!_options.EnableHybrid) { _provider.RemoveByPrefix(region); } else { _hybridProvider.RemoveByPrefix(region); } }