private static void ApplyCachingProvider(CachingProviderType cachingProvider, RepositoryOptionsBuilder builder) { switch (cachingProvider) { case CachingProviderType.MicrosoftInMemory: { builder.UseCachingProvider(new InMemoryCacheProvider()); break; } case CachingProviderType.Redis: { var redis = new RedisCacheProvider(allowAdmin: true, defaultDatabase: 0, expiry: null); redis.Server.FlushAllDatabases(); builder.UseCachingProvider(redis); break; } default: throw new ArgumentOutOfRangeException(nameof(cachingProvider)); } }
private static void ApplyCachingProvider(CachingProviderType cachingProvider, RepositoryOptionsBuilder builder) { switch (cachingProvider) { case CachingProviderType.MicrosoftInMemory: { builder.UseInMemoryCache(); break; } case CachingProviderType.Redis: { builder.UseRedis(options => { options .WithEndPoint("localhost") .WithDefaultDatabase(0); }); break; } #if NETFULL case CachingProviderType.Memcached: { builder.UseMemcached(options => { options.WithEndPoint("127.0.0.1", 11211); }); break; } #endif case CachingProviderType.Couchbase: { builder.UseCouchbase(options => { options .WithEndPoint("http://localhost:8091") .WithBucketName("default") .WithUsername("default") .WithPassword("password"); }); break; } default: throw new ArgumentOutOfRangeException(nameof(cachingProvider)); } }
private static void ApplyCachingProvider(CachingProviderType cachingProvider, RepositoryOptionsBuilder builder) { switch (cachingProvider) { case CachingProviderType.MicrosoftInMemory: { builder.UseCachingProvider(new InMemoryCacheProvider()); break; } case CachingProviderType.Redis: { var provider = new RedisCacheProvider(allowAdmin: true, defaultDatabase: 0, expiry: null); provider.Cache.Server.FlushAllDatabases(); builder.UseCachingProvider(provider); break; } case CachingProviderType.Memcached: { var provider = new MemcachedCacheProvider("127.0.0.1", 11211); provider.Cache.Client.FlushAll(); builder.UseCachingProvider(provider); break; } case CachingProviderType.Couchbase: { var provider = new CouchbaseCacheProvider("http://localhost:8091", "default", "password"); using (var bucket = provider.Cache.Cluster.OpenBucket()) { bucket.CreateManager("default", "password").Flush(); } builder.UseCachingProvider(provider); break; } default: throw new ArgumentOutOfRangeException(nameof(cachingProvider)); } }
private static void ClearCacheProvider(CachingProviderType cachingProvider) { #if NETFULL if (cachingProvider == CachingProviderType.Memcached) { MemcachedHelper.ClearDatabase("127.0.0.1", 11211); } #endif if (cachingProvider == CachingProviderType.Redis) { RedisHelper.ClearDatabase("localhost", 0); } if (cachingProvider == CachingProviderType.Couchbase) { CouchbaseHelper.ClearDatabase("http://localhost:8091", "default", "password", "default"); } }
public async Task KeyExpireAsync(IEnumerable <string> cacheKeys, int seconds) { var operationId = s_diagnosticListener.WriteSetCacheBefore(new BeforeSetRequestEventData(CachingProviderType.ToString(), Name, nameof(TrySetAsync), new Dictionary <string, object> { { "cacheKeys", cacheKeys } }, TimeSpan.FromSeconds(seconds))); Exception e = null; try { await BaseKeyExpireAsync(cacheKeys, seconds); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteSetCacheError(operationId, e); } else { s_diagnosticListener.WriteSetCacheAfter(operationId); } } }
public async Task <bool> TrySetAsync <T>(string cacheKey, T cacheValue, TimeSpan expiration) { var operationId = s_diagnosticListener.WriteSetCacheBefore(new BeforeSetRequestEventData(CachingProviderType.ToString(), Name, nameof(TrySetAsync), new Dictionary <string, object> { { cacheKey, cacheValue } }, expiration)); Exception e = null; try { return(await BaseTrySetAsync(cacheKey, cacheValue, expiration)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteSetCacheError(operationId, e); } else { s_diagnosticListener.WriteSetCacheAfter(operationId); } } }
public async Task SetAllAsync <T>(IDictionary <string, T> value, TimeSpan expiration) { var operationId = s_diagnosticListener.WriteSetCacheBefore(new BeforeSetRequestEventData(CachingProviderType.ToString(), Name, nameof(SetAllAsync), value.ToDictionary(k => k.Key, v => (object)v.Value), expiration)); Exception e = null; try { await BaseSetAllAsync(value, expiration); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteSetCacheError(operationId, e); } else { s_diagnosticListener.WriteSetCacheAfter(operationId); } } }
public async Task RemoveByPrefixAsync(string prefix) { var operationId = s_diagnosticListener.WriteRemoveCacheBefore(new BeforeRemoveRequestEventData(CachingProviderType.ToString(), Name, nameof(RemoveByPrefixAsync), new[] { prefix })); Exception e = null; try { await BaseRemoveByPrefixAsync(prefix); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteRemoveCacheError(operationId, e); } else { s_diagnosticListener.WriteRemoveCacheAfter(operationId); } } }
public async Task RemoveAllAsync(IEnumerable <string> cacheKeys) { var operationId = s_diagnosticListener.WriteRemoveCacheBefore(new BeforeRemoveRequestEventData(CachingProviderType.ToString(), Name, nameof(RemoveAllAsync), cacheKeys.ToArray())); Exception e = null; try { await BaseRemoveAllAsync(cacheKeys); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteRemoveCacheError(operationId, e); } else { s_diagnosticListener.WriteRemoveCacheAfter(operationId); } } }
public void Remove(string cacheKey) { var operationId = s_diagnosticListener.WriteRemoveCacheBefore(new BeforeRemoveRequestEventData(CachingProviderType.ToString(), Name, nameof(Remove), new[] { cacheKey })); Exception e = null; try { BaseRemove(cacheKey); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteRemoveCacheError(operationId, e); } else { s_diagnosticListener.WriteRemoveCacheAfter(operationId); } } }
protected virtual void BeforeTest(CachingProviderType cachingProvider) { }
public async Task <CacheValue <T> > GetAsync <T>(string cacheKey, Func <Task <T> > dataRetriever, TimeSpan expiration) { var operationId = s_diagnosticListener.WriteGetCacheBefore(new BeforeGetRequestEventData(CachingProviderType.ToString(), Name, nameof(GetAsync), new[] { cacheKey }, expiration)); Exception e = null; try { return(await BaseGetAsync <T>(cacheKey, dataRetriever, expiration)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteGetCacheError(operationId, e); } else { s_diagnosticListener.WriteGetCacheAfter(operationId); } } }
public async Task <IDictionary <string, CacheValue <T> > > GetAllAsync <T>(IEnumerable <string> cacheKeys) { var operationId = s_diagnosticListener.WriteGetCacheBefore(new BeforeGetRequestEventData(CachingProviderType.ToString(), Name, nameof(GetAllAsync), cacheKeys.ToArray())); Exception e = null; try { return(await BaseGetAllAsync <T>(cacheKeys)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteGetCacheError(operationId, e); } else { s_diagnosticListener.WriteGetCacheAfter(operationId); } } }
public CacheValue <T> Get <T>(string cacheKey) { var operationId = s_diagnosticListener.WriteGetCacheBefore(new BeforeGetRequestEventData(CachingProviderType.ToString(), Name, nameof(Get), new[] { cacheKey })); Exception e = null; try { return(BaseGet <T>(cacheKey)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteGetCacheError(operationId, e); } else { s_diagnosticListener.WriteGetCacheAfter(operationId); } } }
public async Task FlushAsync() { var operationId = s_diagnosticListener.WriteFlushCacheBefore(new EventData(CachingProviderType.ToString(), Name, nameof(FlushAsync))); Exception e = null; try { await BaseFlushAsync(); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteFlushCacheError(operationId, e); } else { s_diagnosticListener.WriteFlushCacheAfter(operationId); } } }
protected override void AfterTest(CachingProviderType cachingProvider) { ClearCacheProvider(cachingProvider); }
public async Task <bool> ExistsAsync(string cacheKey) { var operationId = s_diagnosticListener.WriteExistsCacheBefore(new BeforeExistsRequestEventData(CachingProviderType.ToString(), Name, nameof(ExistsAsync), cacheKey)); Exception e = null; try { var flag = await BaseExistsAsync(cacheKey); return(flag); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteExistsCacheError(operationId, e); } else { s_diagnosticListener.WriteExistsCacheAfter(operationId); } } }
public async Task <IDictionary <string, CacheValue <T> > > GetByPrefixAsync <T>(string prefix) { var operationId = s_diagnosticListener.WriteGetCacheBefore(new BeforeGetRequestEventData(CachingProviderType.ToString(), Name, nameof(GetByPrefixAsync), new[] { prefix })); Exception e = null; try { return(await BaseGetByPrefixAsync <T>(prefix)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteGetCacheError(operationId, e); } else { s_diagnosticListener.WriteGetCacheAfter(operationId); } } }
public async Task <object> GetAsync(string cacheKey, Type type) { var operationId = s_diagnosticListener.WriteGetCacheBefore(new BeforeGetRequestEventData(CachingProviderType.ToString(), Name, "GetAsync_Type", new[] { cacheKey })); Exception e = null; try { return(await BaseGetAsync(cacheKey, type)); } catch (Exception ex) { e = ex; throw; } finally { if (e != null) { s_diagnosticListener.WriteGetCacheError(operationId, e); } else { s_diagnosticListener.WriteGetCacheAfter(operationId); } } }
protected virtual void AfterTest(CachingProviderType cachingProvider) { }