public void ClearCacheTest()
        {
            // set up cache with an initial value
            var cache       = new InstanceByKeyCache <string, string>();
            var key         = "randomKey";
            var cachedValue = "Initial value";

            // get value from cache and check it matches initial
            var value = cache.Get(key, (localKey) =>
            {
                return(cachedValue);
            }, CacheDuration);

            Assert.AreEqual("Initial value", value);

            // clear the cache
            cache.Clear();

            // change the cached value
            cachedValue = "Changed value";

            // check that it returns the changed value
            value = cache.Get(key, (localKey) =>
            {
                return(cachedValue);
            }, CacheDuration);
            Assert.AreEqual("Changed value", value);
        }
 /// <summary>
 /// Static constructor.
 /// </summary>
 static TranslationHelper()
 {
     TranslationNodeIds           = new InstanceByKeyCache <int, NodeAndCulture>();
     TranslationCulturesByNodeIds = new InstanceByKeyCache <IEnumerable <string>, int>();
     TranslationFolderNodeIds     = new InstanceByKeyCache <int?, int>();
     TranslateFolderInvalidator   = new InvalidatorByParentPage <int?>(
         TranslationFolderNodeIds);
     Translations = new InstanceByKeyCache <string, string>();
 }
 public ArchetypeValueConnector(IDataTypeService dataTypeService, IMacroParser macroParser, Lazy <ValueConnectorCollection> valueConnectors)
 {
     dataTypeCacheDuration           = TimeSpan.FromSeconds(30);
     archetypeConfigPreValuesByDtdId = new InstanceByKeyCache <string, int>();
     dataTypeDefinitionsById         = new InstanceByKeyCache <DataTypeDefinition, Guid>();
     _dataTypeService     = dataTypeService;
     _macroParser         = macroParser;
     _valueConnectorsLazy = valueConnectors;
 }
        public void GetValueTest()
        {
            var cache = new InstanceByKeyCache <string, string>();
            var key   = "hi";
            var value = cache.Get(key, (localKey) =>
            {
                return("Hello");
            }, CacheDuration);

            Assert.AreEqual("Hello", value);
        }
        public void CacheByArrayKeyTest()
        {
            var cache = new InstanceByKeyCache <string, ArrayKey <int> >();
            var key1  = new ArrayKey <int>(new[] { 1, 2, 3 });
            var key2  = new ArrayKey <int>(new[] { 1, 2, 3 });
            var value = cache.Get(key1, (localKey) =>
            {
                return("First");
            }, CacheDuration);

            value = cache.Get(key2, (localKey) =>
            {
                return("Second");
            }, CacheDuration);
            Assert.AreEqual("First", value);
        }
 /// <summary>
 /// Primary constructor.
 /// </summary>
 /// <param name="cache">
 /// The cache to invalidate.
 /// </param>
 public InvalidatorByPage(InstanceByKeyCache <T, int> cache)
 {
     this.Cache = cache;
     UmbracoCachingHandlers.RegisterContentByPageInvalidator(this);
 }