public ContentSnippet Get(SiteConfigSetting snippetType) { try { return(this.Context.ContentSnippet.FirstOrDefault(x => x.SnippetType == snippetType)); } catch (Exception ex) { Log.Fatal(ex); throw new Exception("DB error", ex.InnerException); } }
public string GetSnippet(SiteConfigSetting snippetType) { var cacheKey = this.BuildCacheKey(snippetType); if (this.memoryCache.TryGetValue(cacheKey, out string snippet)) { return(snippet); } else { var dbModel = this.contentSnippetRepository.Get(snippetType); if (dbModel == null) { return(string.Empty); } this.memoryCache.Set(cacheKey, dbModel.Content); return(dbModel.Content); } }
private string BuildCacheKey(SiteConfigSetting snippetType) { return(string.Format("{0}{1}", SnippetCachePrefix, snippetType.ToString())); }
public void ClearSnippetCache(SiteConfigSetting snippetType) { var cacheKey = this.BuildCacheKey(snippetType); this.memoryCache.Remove(cacheKey); }