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);
        }
Exemplo n.º 2
0
        public void TestReadWriteMapCache()
        {
            var logger = LogManager.GetCurrentClassLogger();
            var cache  = new CacheService(logger, "TEST_CACHE", true);
            var key    = "THE_KEY";
            var value  = "THE_VALUE";

            cache.Add(key, value);

            // key and value should be present as keys
            Assert.IsTrue(cache.ContainsKey(key));
            Assert.IsTrue(cache.ContainsKey(value));

            // should be able to get the values
            Assert.AreEqual(value, cache.GetValue(key));
            Assert.AreEqual(key, cache.GetValue(value));
        }
Exemplo n.º 3
0
        public void TestPersistCache()
        {
            var logger = LogManager.GetCurrentClassLogger();
            var cache  = new CacheService(logger, "TEST_CACHE", true);
            var key    = "THE_KEY";
            var value  = "THE_VALUE";

            cache.Add(key, value);

            cache.WriteCacheEntries();

            // load the cache again...should read it from the file
            cache = new CacheService(logger, "TEST_CACHE", true);
            Assert.AreEqual(value, cache.GetValue(key));

            // delete the cache file
            cache.DeleteCacheFile();

            //load it again and ensure it is empty
            cache = new CacheService(logger, "TEST_CACHE", true);
            Assert.IsFalse(cache.ContainsKey(key));
        }