Пример #1
0
        private static string GetCacheKey(Widget widget, OutputCacheableAttribute attribute)
        {
            var cacheKey = "Widget." + widget.Id;

            if (attribute.PerPage)
            {
                var page = CurrentRequestData.CurrentPage;
                if (page != null)
                {
                    cacheKey += ".Page:" + page.Id;
                }
            }
            if (attribute.PerUser)
            {
                cacheKey += ".User:" + CurrentRequestData.UserGuid;
            }
            return(cacheKey);
        }
Пример #2
0
 public CachingInfo Get(Widget widget)
 {
     using (MiniProfiler.Current.Step("Get caching info"))
     {
         if (widget == null)
         {
             return(CachingInfo.DoNotCache);
         }
         OutputCacheableAttribute attribute = widget.GetType().GetCustomAttribute <OutputCacheableAttribute>();
         if (attribute == null)
         {
             return(CachingInfo.DoNotCache);
         }
         bool shouldCache = widget.Cache && widget.CacheLength > 0;
         return(new CachingInfo(shouldCache, GetCacheKey(widget, attribute),
                                TimeSpan.FromSeconds(widget.CacheLength),
                                widget.CacheExpiryType));
     }
 }