protected async Task SetCachedQueryResultAsync <TResult>(ICommandOptions options, TResult result, string cachePrefix = null, string cacheSuffix = null) { if (!IsCacheEnabled || result == null || options == null || !options.ShouldUseCache() || !options.HasCacheKey()) { return; } string cacheKey = cachePrefix != null ? cachePrefix + ":" + options.GetCacheKey() : options.GetCacheKey(); if (!String.IsNullOrEmpty(cacheSuffix)) { cacheKey += ":" + cacheSuffix; } await Cache.SetAsync(cacheKey, result, options.GetExpiresIn()).AnyContext(); _logger.Trace(() => $"Set cache: type={ElasticType.Name} key={cacheKey}"); }
protected async Task <TResult> GetCachedQueryResultAsync <TResult>(ICommandOptions options, string cachePrefix = null, string cacheSuffix = null) { if (!IsCacheEnabled || options == null || !options.ShouldReadCache() || !options.HasCacheKey()) { return(default(TResult)); } string cacheKey = cachePrefix != null ? cachePrefix + ":" + options.GetCacheKey() : options.GetCacheKey(); if (!String.IsNullOrEmpty(cacheSuffix)) { cacheKey += ":" + cacheSuffix; } var result = await Cache.GetAsync <TResult>(cacheKey, default(TResult)).AnyContext(); _logger.Trace(() => $"Cache {(result != null ? "hit" : "miss")}: type={ElasticType.Name} key={cacheKey}"); return(result); }