Esempio n. 1
0
        public async Task <IActionResult> CacheContentAsync <T>(
            ComponentServerCached component,
            IEnumerable <int> categoryIds,
            Func <Task <T> > dataLoader,
            int?page = null)
        {
            if (!cachePolicy.CanCache(component, page))
            {
                return(Json(await dataLoader()));
            }

            var key = keyGenerator.ContentGenerateKey(component.Name, categoryIds, page);

            string json;

            if (!string.IsNullOrEmpty(json = contentCache.GetContent(key)))
            {
                return(JsonString(json));
            }

            var content = await dataLoader();

            json = SunJson.Serialize(content);
            contentCache.CacheContent(key, json);
            return(JsonString(json));
        }
Esempio n. 2
0
 public bool CanCache(ComponentServerCached component, int?page = null)
 {
     return(false);
 }
Esempio n. 3
0
 public bool CanCache(ComponentServerCached component, int?page = null)
 {
     return(!page.HasValue || page == 1);
 }