コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 private string BuildCacheKey(SiteConfigSetting snippetType)
 {
     return(string.Format("{0}{1}", SnippetCachePrefix, snippetType.ToString()));
 }
コード例 #4
0
        public void ClearSnippetCache(SiteConfigSetting snippetType)
        {
            var cacheKey = this.BuildCacheKey(snippetType);

            this.memoryCache.Remove(cacheKey);
        }