Ejemplo n.º 1
0
        public IGXWebApiCacheAttribute() : base()
        {
            var      sitePath = CMSPageFactory.GetSitePath();
            Settings settings = Settings.Get(new FileInfo(Path.Combine(sitePath, "settings/settings.xml")));

            TriggerFile = Path.Combine(sitePath, settings.GetSetting <string>("RuntimeCache", "TriggerFile"));
        }
Ejemplo n.º 2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var sitePath = CMSPageFactory.GetSitePath();

            Settings settings = Settings.Get(new FileInfo(Path.Combine(sitePath, "settings/settings.xml")));

            var path = actionContext.Request.RequestUri.LocalPath.ToLowerInvariant();

            ObjectCache cache = MemoryCache.Default;

            var cachedContentObject = cache.Get($"{MEM_CACHE_PREFIX}{path}");

            if (cachedContentObject != null)
            {
                if (cachedContentObject is string cachedContent)
                {
                    var response = actionContext.Request.CreateResponse(HttpStatusCode.OK);
                    response.Content       = new StringContent(cachedContent);
                    actionContext.Response = response;
                    return;
                }
            }


            IGXPageLevelCache pageLevelCache = IGXPageLevelCache.Get(TriggerFile);
            PageCache         pageCache      = pageLevelCache.GetPageCacheSettings(path);

            UseCache = settings.GetSetting <bool>("RuntimeCache", "UseRuntimeCache") && pageCache != null && pageCache.Cache;

            if (!UseCache)
            {
                Duration = 0;
            }
            else
            {
                int durationSettings = pageCache.CacheTime > 0 ? pageCache.CacheTime : settings.GetSetting <int>("RuntimeCache", "ExpireTime");
                Duration = durationSettings;
            }


            base.OnActionExecuting(actionContext);
        }
Ejemplo n.º 3
0
 public static string GetSitePath()
 {
     return(CMSPageFactory.GetSitePath());
 }