コード例 #1
0
		public void StartCacheProcesses()
        {
            factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            shortCacheManager = factory.Create("ShortInMemoryPersistence");
            smallCacheManager = factory.Create("SmallInMemoryPersistence");

            expiredKeys = "";
            expiredValues = "";
            removalReasons = "";
        }
コード例 #2
0
        public void StartCacheProcesses()
        {
            factory           = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            shortCacheManager = factory.Create("ShortInMemoryPersistence");
            smallCacheManager = factory.Create("SmallInMemoryPersistence");

            expiredKeys    = "";
            expiredValues  = "";
            removalReasons = "";
        }
コード例 #3
0
        public void GetCacheManagerWithNullEncryption()
        {
            CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            ICacheManager       mgr     = factory.Create("InMemoryPersistenceWithNullEncryption");

            CacheManagerTest(mgr);
        }
コード例 #4
0
        public void WillThrowExceptionIfCannotFindSection()
        {
            CacheManagerFactory factory2 = new CacheManagerFactory(new DictionaryConfigurationSource());

            factory2.Create("some name");

            Assert.Fail("Should have thrown ConfigurationErrorsException");
        }
コード例 #5
0
        public void WillThrowExceptionIfCannotFindSection()
        {
            CacheManagerFactory factory2 = new CacheManagerFactory(new DictionaryConfigurationSource());

            factory2.Create("some name");

            Assert.Fail("Should have thrown ConfigurationErrorsException");
        }
コード例 #6
0
		public void TestInitialize()
        {
			CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
			cache = factory.Create("InDatabasePersistence");
			cache.Flush();
            wasCalledBack = false;
            initializationCount = 0;
        }
コード例 #7
0
        public void CreateCache()
        {
            removedKey = null;
            expiredValue = null;
            removalReason = CacheItemRemovedReason.Unknown;

            factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            cacheMgr = (CacheManager)factory.Create("SmallInMemoryPersistence");
        }
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfCacheManager()
        {
            cacheManagerData.Name = "New Name";
            configurationSource.DoSourceChanged(new string[]{CacheManagerSettings.SectionName});

            CacheManagerFactory factory = new CacheManagerFactory(serviceLcoator);
            ICacheManager cacheManager = factory.Create("New Name");
            Assert.IsNotNull(cacheManager);
        }
コード例 #9
0
        public void CallingDifferentFactoryTwiceReturnsDifferentInstances()
        {
            CacheManager cacheOne = factory.Create("InMemoryPersistence");

            CacheManagerFactory secondFactory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            CacheManager cacheTwo = secondFactory.Create("InMemoryPersistence");

            Assert.IsFalse(object.ReferenceEquals(cacheOne, cacheTwo), "Different factories should always return different instances for same instance name");
        }
コード例 #10
0
        public void CallingDifferentFactoryTwiceReturnsDifferentInstances()
        {
            CacheManager cacheOne = factory.Create("InMemoryPersistence");

            CacheManagerFactory secondFactory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            CacheManager        cacheTwo      = secondFactory.Create("InMemoryPersistence");

            Assert.IsFalse(object.ReferenceEquals(cacheOne, cacheTwo), "Different factories should always return different instances for same instance name");
        }
        public void TestInitialize()
        {
            CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());

            cache = factory.Create("InDatabasePersistence");
            cache.Flush();
            wasCalledBack       = false;
            initializationCount = 0;
        }
コード例 #12
0
        public void CreateCache()
        {
            removedKey    = null;
            expiredValue  = null;
            removalReason = CacheItemRemovedReason.Unknown;

            factory  = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            cacheMgr = (CacheManager)factory.Create("SmallInMemoryPersistence");
        }
コード例 #13
0
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfCacheManager()
        {
            cacheManagerData.Name = "New Name";
            configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName });

            CacheManagerFactory factory      = new CacheManagerFactory(serviceLcoator);
            ICacheManager       cacheManager = factory.Create("New Name");

            Assert.IsNotNull(cacheManager);
        }
        void CacheManagerTest(string instanceName)
        {
            CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            ICacheManager mgr = factory.Create(instanceName);

            string key = "key1";
            string val = "value123";

            mgr.Add(key, val);

            string result = (string)mgr.GetData(key);
            Assert.AreEqual(val, result, "result");
        }
        public void CanCreateIsolatedStorageCacheManager()
        {
            cacheManager.Add("bab", "foo");
            Assert.AreEqual(1, cacheManager.Count);

			CacheManagerFactory differentFactory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            CacheManager differentCacheManager = differentFactory.Create("InIsoStorePersistence");
            
            int count = differentCacheManager.Count;
            differentCacheManager.Dispose();

            Assert.AreEqual(1, count, "If we actually persisted added item, different cache manager should see item, too.");
        }
コード例 #16
0
        private void CacheManagerTest(string instanceName)
        {
            CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            CacheManager        mgr     = factory.Create(instanceName);

            string key = "key1";
            string val = "value123";

            mgr.Add(key, val);

            string result = (string)mgr.GetData(key);

            Assert.AreEqual(val, result, "result");
        }
コード例 #17
0
        public void CanCreateIsolatedStorageCacheManager()
        {
            cacheManager.Add("bab", "foo");
            Assert.AreEqual(1, cacheManager.Count);

            CacheManagerFactory differentFactory      = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            CacheManager        differentCacheManager = differentFactory.Create("InIsoStorePersistence");

            int count = differentCacheManager.Count;

            differentCacheManager.Dispose();

            Assert.AreEqual(1, count, "If we actually persisted added item, different cache manager should see item, too.");
        }
コード例 #18
0
        private ICacheManager GetCacheManager()
        {
            ICacheManager cacheManager;

            lock (cacheLock)
            {
                if (!cacheManagers.ContainsKey(Group))
                {
                    CacheManagerFactory cacheManagerFactory = new CacheManagerFactory(GetConfigurationSource());
                    cacheManagers.Add(Group, cacheManagerFactory.Create(Group));
                }
                cacheManager = cacheManagers[Group];
            }
            return(cacheManager);
        }
コード例 #19
0
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfBackingStore()
        {
            MockCustomStorageBackingStore.Instantiated = false;

            cacheSettings.BackingStores.Remove("Null Storage");
            cacheSettings.BackingStores.Add(new CustomCacheStorageData("Custom Store", typeof(MockCustomStorageBackingStore)));
            cacheManagerData.CacheStorage = "Custom Store";

            configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName });

            CacheManagerFactory factory      = new CacheManagerFactory(serviceLcoator);
            ICacheManager       cacheManager = factory.Create(cacheSettings.DefaultCacheManager);

            Assert.IsTrue(MockCustomStorageBackingStore.Instantiated);
        }
コード例 #20
0
        public static ICacheManager Create(string configSource, string cacheName)
        {
            ICacheManager           cache;
            FileConfigurationSource config = new FileConfigurationSource(configSource);
            CacheManagerFactory     cf     = new CacheManagerFactory(config);

            if (string.IsNullOrEmpty(cacheName))
            {
                cache = cf.Create(cacheName);
            }
            else
            {
                cache = cf.CreateDefault();
            }

            return(cache);
        }
コード例 #21
0
        public CacheManager GetCacheManagerByGroupName(string groupName)
        {
            lock (caches)
            {
                if (caches.ContainsKey(groupName))
                {
                    return(caches[groupName]);
                }

                CacheManagerFactory cacheManagerFactory = new CacheManagerFactory(GetCacheConfiguration(groupName));
                CacheManager        cacheManager        = cacheManagerFactory.Create(groupName);
                if (cacheManager != null)
                {
                    caches.Add(groupName, cacheManager);
                }
                return(cacheManager);
            }
        }
コード例 #22
0
        public IDeliveryClient Get(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (!_cache.TryGetValue(name, out var client))
            {
                client = _innerDeliveryClientFactory.Get(name);
                if (client != null)
                {
                    var cacheOptions = _deliveryCacheOptions.Get(name);
                    if (cacheOptions.Name == name)
                    {
                        // Build caching services according to the options
                        IDeliveryCacheManager manager;
                        if (cacheOptions.CacheType == CacheTypeEnum.Memory)
                        {
                            var memoryCache = GetNamedServiceOrDefault <IMemoryCache>(name);
                            manager = CacheManagerFactory.Create(memoryCache, Options.Create(cacheOptions));
                        }
                        else
                        {
                            var distributedCache = GetNamedServiceOrDefault <IDistributedCache>(name);
                            manager = CacheManagerFactory.Create(distributedCache, Options.Create(cacheOptions));
                        }

                        // Decorate the client with a caching layer
                        client = new DeliveryClientCache(manager, client);

                        _cache.TryAdd(name, client);
                    }
                }
            }

            return(client);
        }
コード例 #23
0
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfStorageEncryptionProvider()
        {
            MockStorageEncryptionProvider.Instantiated = false;

            storageEncryptionProviderData = new MockStorageEncryptionProviderData("Storage Encryption");
            cacheSettings.EncryptionProviders.Add(storageEncryptionProviderData);

            IsolatedStorageCacheStorageData isolatedStoreData = new IsolatedStorageCacheStorageData();

            isolatedStoreData.Name              = "Isolated Storage";
            isolatedStoreData.PartitionName     = "entlib";
            isolatedStoreData.StorageEncryption = storageEncryptionProviderData.Name;

            cacheSettings.BackingStores.Add(isolatedStoreData);

            cacheManagerData.CacheStorage = isolatedStoreData.Name;
            configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName });

            CacheManagerFactory factory      = new CacheManagerFactory(serviceLcoator);
            ICacheManager       cacheManager = factory.Create(cacheSettings.DefaultCacheManager);

            Assert.IsTrue(MockStorageEncryptionProvider.Instantiated);
        }
        public void TestInitialize()
        {
            CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());

            cache = factory.Create("InDatabasePersistence");
        }
コード例 #25
0
        public void Create_MemoryCache()
        {
            var deliveryCacheManager = CacheManagerFactory.Create(_memoryCache, _options);

            deliveryCacheManager.Should().NotBeNull();
        }
		public void CreateCacheManager()
        {
			factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
            cacheManager = factory.Create("InIsoStorePersistence");
            cacheManager.Flush();
        }
 public void GetCacheManagerWithNullEncryption()
 {
     CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
     ICacheManager mgr = factory.Create("InMemoryPersistenceWithNullEncryption");
     CacheManagerTest(mgr);
 }
コード例 #28
0
 public void TestInitialize()
 {
     CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
     cache = (CacheManager)factory.Create("InDatabasePersistence");
 }
コード例 #29
0
        public void CreateNamedCacheInstance()
        {
            CacheManager cache = factory.Create("InMemoryPersistence");

            Assert.IsNotNull(cache, "Should have created caching instance through factory");
        }
コード例 #30
0
 public void CreateCacheManager()
 {
     factory      = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration());
     cacheManager = factory.Create("InIsoStorePersistence");
     cacheManager.Flush();
 }
コード例 #31
0
        public void Create_DistributedCache()
        {
            var deliveryCacheManager = CacheManagerFactory.Create(_distributedCache, _options);

            deliveryCacheManager.Should().NotBeNull();
        }
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfStorageEncryptionProvider()
        {
            MockStorageEncryptionProvider.Instantiated = false;

            storageEncryptionProviderData = new MockStorageEncryptionProviderData("Storage Encryption");
            cacheSettings.EncryptionProviders.Add(storageEncryptionProviderData);
            
            IsolatedStorageCacheStorageData isolatedStoreData = new IsolatedStorageCacheStorageData();
            isolatedStoreData.Name = "Isolated Storage";
            isolatedStoreData.PartitionName = "entlib";
            isolatedStoreData.StorageEncryption = storageEncryptionProviderData.Name;

            cacheSettings.BackingStores.Add(isolatedStoreData);
            
            cacheManagerData.CacheStorage = isolatedStoreData.Name;
            configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName });

            CacheManagerFactory factory = new CacheManagerFactory(serviceLcoator);
            ICacheManager cacheManager = factory.Create(cacheSettings.DefaultCacheManager);
            Assert.IsTrue(MockStorageEncryptionProvider.Instantiated);
        }
        public void ThenReturnsNewlyConfiguredInstanceAfterReconfigureOfBackingStore()
        {
            MockCustomStorageBackingStore.Instantiated = false;

            cacheSettings.BackingStores.Remove("Null Storage");
            cacheSettings.BackingStores.Add(new CustomCacheStorageData("Custom Store", typeof(MockCustomStorageBackingStore)));
            cacheManagerData.CacheStorage = "Custom Store";

            configurationSource.DoSourceChanged(new string[] { CacheManagerSettings.SectionName });

            CacheManagerFactory factory = new CacheManagerFactory(serviceLcoator);
            ICacheManager cacheManager = factory.Create(cacheSettings.DefaultCacheManager);
            Assert.IsTrue(MockCustomStorageBackingStore.Instantiated);
        }