示例#1
0
        public bool TryFindPage(string url, out IPage page)
        {
            page = null;

            string cacheKey = GetCacheKey("Page", url);

            if (!HasPageChanged(url))
            {
                //Get page from Cache
                page = (IPage)CacheService.GetItem(cacheKey);
                return(true);
            }
            else
            {
                //Get page from broker database
                string pageContentFromBroker = GetStringContentFromBrokerByUrl(url);

                if (!pageContentFromBroker.Equals(String.Empty))
                {
                    page = GetIPageObject(pageContentFromBroker);
                    CacheService.AddItem(cacheKey, page);
                    return(true);
                }
            }



            return(false);
        }
示例#2
0
        public bool TryGetPageContent(string tcmUri, out string pageContent)
        {
            pageContent = string.Empty;

            string cacheKey = GetCacheKey("PageContent", tcmUri);

            if (!HasPageChanged(new TcmUri(tcmUri)))
            {
                pageContent = (string)CacheService.GetItem(cacheKey);
                return(true);
            }
            else
            {
                string tempPageContent = GetStringContentFromBrokerByUri(tcmUri);
                if (tempPageContent != string.Empty)
                {
                    pageContent = tempPageContent;
                    CacheService.AddItem(cacheKey, pageContent);
                    return(true);
                }
            }


            return(false);
        }
示例#3
0
        public bool TryGetPage(string tcmUri, out IPage page)
        {
            page = null;

            string cacheKey = GetCacheKey("Page", tcmUri);

            if (!HasPageChanged(new TcmUri(tcmUri)))
            {
                page = (IPage)CacheService.GetItem(cacheKey);
                return(true);
            }
            else
            {
                string tempPageContent = GetStringContentFromBrokerByUri(tcmUri);
                if (tempPageContent != string.Empty)
                {
                    page = GetIPageObject(tempPageContent);
                    CacheService.AddItem(cacheKey, page);

                    return(true);
                }
            }


            return(false);
        }
        public string ResolveLink(string componentUri)
        {
            TcmUri uri = new TcmUri(componentUri);

            if (!uri.Equals(emptyTcmUri))
            {
                //Cache cache = HttpContext.Current.Cache;
                string cacheKey = String.Format(CACHEKEY_FORMAT, componentUri);
                if (CacheService.ContainsKey(cacheKey))
                {
                    return((String)CacheService.GetItem(cacheKey));
                }
                else
                {
                    Link link = componentLink.GetLink(uri.ToString());
                    if (!link.IsResolved)
                    {
                        return(null);
                    }
                    //cache.Insert(cacheKey, link.Url, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero); //TODO should this be configurable?
                    CacheService.AddItem(cacheKey, link.Url, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero);                     //TODO should this be configurable?
                    return(link.Url);
                }
            }

            return(null);
        }
示例#5
0
        public CachingRoutes(CacheService myCache) : base("/caching")
        {
            _myCache = myCache;

            Get["/"] = x =>
            {
                var cacheData = new CacheDemo()
                {
                    WhenRequested = DateTime.Now
                };
                return(View["caching/index.html", cacheData]);
            };

            Before += ctx =>
            {
                string key = ctx.Request.Path;

                var cacheObject = _myCache.GetItem(key);
                return(cacheObject);
            };

            After += ctx =>
            {
                if (ctx.Response.StatusCode != HttpStatusCode.OK)
                {
                    return;
                }

                string key = ctx.Request.Path;
                if (_myCache.GetItem(key) == null)
                {
                    _myCache.AddItem(key, ctx.Response);
                }
            };
        }
示例#6
0
        public bool TryFindPageContent(string url, out string pageContent)
        {
            pageContent = string.Empty;

            string cacheKey = GetCacheKey("PageContent", url);

            if (!HasPageChanged(url))
            {
                pageContent = (string)CacheService.GetItem(cacheKey);
                return(true);
            }
            else
            {
                string tempPageContent = GetStringContentFromBrokerByUrl(url);
                if (tempPageContent != string.Empty)
                {
                    pageContent = tempPageContent;
                    CacheService.AddItem(cacheKey, pageContent);
                    return(true);
                }
            }
            return(false);
        }