public void CanScavengeInBackground() { CacheItem item1 = new CacheItem("key1", "value1", CacheItemPriority.Low, null); CacheItem item2 = new CacheItem("key2", "value2", CacheItemPriority.Normal, null); CacheItem item3 = new CacheItem("key3", "value3", CacheItemPriority.High, null); AddCacheItem("key1", item1); AddCacheItem("key2", item2); AddCacheItem("key3", item3); TestConfigurationContext context = new TestConfigurationContext(); CachingConfigurationView view = new CachingConfigurationView(context); view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 2; view.GetCacheManagerSettings().CacheManagers["test"].NumberToRemoveWhenScavenging = 1; CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view); ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this); BackgroundScheduler scheduler = new BackgroundScheduler(null, scavenger); scheduler.Start(); Thread.Sleep(500); scheduler.StartScavenging(); Thread.Sleep(250); scheduler.Stop(); Thread.Sleep(250); Assert.AreEqual("key1", scavengedKeys); }
/// <summary> /// Initializes a new instance of the <see cref="IsolatedStorageBackingStore"/> class given the configuration data /// </summary> /// <param name="configurationView">An <see cref="CachingConfigurationView"></see> object</param> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); ArgumentValidation.CheckExpectedType(configurationView, typeof(CachingConfigurationView)); CachingConfigurationView cachingConfigurationView = (CachingConfigurationView)configurationView; IsolatedStorageCacheStorageData isoStoreConfigurationData = (IsolatedStorageCacheStorageData)cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager); if (isoStoreConfigurationData.PartitionName == null) { throw new ConfigurationException(SR.IsolatedStoreAreaNameNullException(isoStoreConfigurationData.Name)); } if (isoStoreConfigurationData.PartitionName.Length == 0) { throw new ConfigurationException(SR.IsolatedStoreAreaNameEmptyException(isoStoreConfigurationData.Name)); } this.storageAreaName = isoStoreConfigurationData.PartitionName; if (isoStoreConfigurationData.StorageEncryption != null) { StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext); this.encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager); } Initialize(); }
public void WillRemoveMultipleEligibleForScavenging() { TestConfigurationContext context = new TestConfigurationContext(); CachingConfigurationView view = new CachingConfigurationView(context); view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 2; view.GetCacheManagerSettings().CacheManagers["test"].NumberToRemoveWhenScavenging = 3; CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view); ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this); CacheItem itemToRemove = new CacheItem("key1", "value", CacheItemPriority.High, null); CacheItem itemToRemain = new CacheItem("key2", "value", CacheItemPriority.Low, null); CacheItem itemToRemoveAlso = new CacheItem("key3", "value", CacheItemPriority.Normal, null); itemToRemove.MakeEligibleForScavenging(); itemToRemain.MakeEligibleForScavenging(); itemToRemoveAlso.MakeEligibleForScavenging(); AddCacheItem("key1", itemToRemove); AddCacheItem("key2", itemToRemain); AddCacheItem("key3", itemToRemoveAlso); scavenger.DoScavenging(); Assert.AreEqual("key2key3key1", scavengedKeys); }
/// <summary> /// Initializes this provider with the correct Symmetric Cryptographic Provider Factory /// to create the correct cryptographic provider to encrypt or decrypt the data stored /// in the cache. /// </summary> /// <param name="configurationView">A <see cref="CachingConfigurationView"></see> object</param> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); ArgumentValidation.CheckExpectedType(configurationView, typeof(CachingConfigurationView)); cachingConfigurationView = (CachingConfigurationView)configurationView; }
/// <summary> /// <para>Gets the <see cref="Type"/> of the <see cref="IStorageEncryptionProvider"/> for the factory to create for a <see cref="CacheManager"/>.</para> /// </summary> /// <param name="cacheManagerName"> /// <para>The name of the cache manager to create the <see cref="IStorageEncryptionProvider"/>.</para> /// </param> /// <returns> /// <para>The <see cref="Type"/> of the <see cref="IStorageEncryptionProvider"/> to create.</para> /// </returns> protected override Type GetConfigurationType(string cacheManagerName) { CachingConfigurationView view = (CachingConfigurationView)CreateConfigurationView(); StorageEncryptionProviderData data = view.GetStorageEncryptionProviderData(cacheManagerName); return(GetType(data.TypeName)); }
/// <summary> /// Initializes this provider with the correct Symmetric Cryptographic Provider Factory /// to create the correct cryptographic provider to encrypt or decrypt the data stored /// in the cache. /// </summary> /// <param name="configurationView">A <see cref="CachingConfigurationView"></see> object</param> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); ArgumentValidation.CheckExpectedType(configurationView, typeof (CachingConfigurationView)); cachingConfigurationView = (CachingConfigurationView) configurationView; }
public void WillScavenge() { CacheItem item1 = new CacheItem("key1", "value1", CacheItemPriority.NotRemovable, null); CacheItem item2 = new CacheItem("key2", "value2", CacheItemPriority.High, null); CacheItem item3 = new CacheItem("key3", "value3", CacheItemPriority.Normal, null); CacheItem item4 = new CacheItem("key4", "value4", CacheItemPriority.Low, null); AddCacheItem("key1", item1); AddCacheItem("key2", item2); AddCacheItem("key3", item3); AddCacheItem("key4", item4); TestConfigurationContext context = new TestConfigurationContext(); CachingConfigurationView view = new CachingConfigurationView(context); view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 1; view.GetCacheManagerSettings().CacheManagers["test"].NumberToRemoveWhenScavenging = 2; CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view); ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this); scavenger.DoScavenging(); Assert.AreEqual("key4key3", scavengedKeys); }
public void WillNotDieIfNotEnoughItemsToScavenge() { TestConfigurationContext context = new TestConfigurationContext(); CachingConfigurationView view = new CachingConfigurationView(context); view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 2; view.GetCacheManagerSettings().CacheManagers["test"].NumberToRemoveWhenScavenging = 4; CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view); ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this); CacheItem itemToRemove = new CacheItem("key1", "value", CacheItemPriority.High, null); CacheItem itemToRemain = new CacheItem("key2", "value", CacheItemPriority.Low, null); CacheItem itemToRemoveAlso = new CacheItem("key3", "value", CacheItemPriority.Normal, null); itemToRemove.MakeEligibleForScavenging(); itemToRemain.MakeEligibleForScavenging(); itemToRemoveAlso.MakeEligibleForScavenging(); AddCacheItem("key1", itemToRemove); AddCacheItem("key2", itemToRemain); AddCacheItem("key3", itemToRemoveAlso); scavenger.DoScavenging(); Assert.AreEqual("key2key3key1", scavengedKeys); }
public string MapName(string name, IConfigurationSource configurationSource) { if (name == null) { CachingConfigurationView view = new CachingConfigurationView(configurationSource); return(view.DefaultCacheManager); } return(name); }
public static CacheManager Create(string name, IConfigurationSource configurationSource) { CachingConfigurationView configurationView = new CachingConfigurationView(configurationSource); CacheManagerData objectConfiguration = configurationView.GetCacheManagerData(name); IBackingStore backingStore = EnterpriseLibraryFactory.BuildUp <IBackingStore>(objectConfiguration.CacheStorage, configurationSource); return(new MockCacheManagerFactoryHelper().BuildCacheManager( name, backingStore, objectConfiguration.MaximumElementsInCacheBeforeScavenging, objectConfiguration.NumberToRemoveWhenScavenging, objectConfiguration.ExpirationPollFrequencyInSeconds, new CachingInstrumentationProvider())); }
/// <summary> /// Initializes a new instance of the <see cref="DataBackingStore"/> class /// with the specified configuration information. /// </summary> /// <param name="configurationView">A <see cref="CachingConfigurationView"></see> object</param> /// <exception cref="System.Configuration.ConfigurationException">Reflects any failures to read configuration information</exception> /// <remarks>Other exceptions thrown depend on the implementation of the underlying database.</remarks> public override void Initialize(ConfigurationView configurationView) { ArgumentValidation.CheckForNullReference(configurationView, "configurationView"); ArgumentValidation.CheckExpectedType(configurationView, typeof(CachingConfigurationView)); CachingConfigurationView cachingConfigurationView = (CachingConfigurationView)configurationView; DataCacheStorageData dataConfiguration = (DataCacheStorageData)cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager); partitionName = dataConfiguration.PartitionName; DatabaseProviderFactory dataFactory = new DatabaseProviderFactory(cachingConfigurationView.ConfigurationContext); database = dataFactory.CreateDatabase(dataConfiguration.DatabaseInstanceName); if (dataConfiguration.StorageEncryption != null) { StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext); encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager); } }
public void WillRemoveSingleItemFromCache() { TestConfigurationContext context = new TestConfigurationContext(); CachingConfigurationView view = new CachingConfigurationView(context); view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 0; CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view); ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this); CacheItem itemToRemove = new CacheItem("key", "value", CacheItemPriority.Low, null); itemToRemove.MakeEligibleForScavenging(); AddCacheItem("key", itemToRemove); scavenger.DoScavenging(); Assert.AreEqual("key", scavengedKeys); }
public static CacheManager Create(string name, IConfigurationSource configurationSource) { CachingConfigurationView configurationView = new CachingConfigurationView(configurationSource); CacheManagerData objectConfiguration = configurationView.GetCacheManagerData(name); IBackingStore backingStore = EnterpriseLibraryFactory.BuildUp<IBackingStore>(objectConfiguration.CacheStorage, configurationSource); return new MockCacheManagerFactoryHelper().BuildCacheManager( name, backingStore, objectConfiguration.MaximumElementsInCacheBeforeScavenging, objectConfiguration.NumberToRemoveWhenScavenging, objectConfiguration.ExpirationPollFrequencyInSeconds, new CachingInstrumentationProvider()); }
protected override StorageEncryptionProviderData GetConfiguration(string name, IConfigurationSource configurationSource) { CachingConfigurationView view = new CachingConfigurationView(configurationSource); return(view.GetStorageEncryptionProviderData(name)); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Returns the default cache manager name from the configuration in the <paramref name="configSource"/>, if the /// value for <paramref name="name"/> is <see langword="null"/> (<b>Nothing</b> in Visual Basic). /// </summary> /// <param name="name">The current name.</param> /// <param name="configurationSource">The source for configuration information.</param> /// <returns>The default cache manager name if <paramref name="name"/> is <see langword="null"/> (<b>Nothing</b> in Visual Basic), /// otherwise the original value for <b>name</b>.</returns> public string MapName(string name, IConfigurationSource configurationSource) { if (name == null) { CachingConfigurationView view = new CachingConfigurationView(configurationSource); return view.DefaultCacheManager; } return name; }
public CacheCapacityScavengingPolicy(string cacheManagerName, CachingConfigurationView latestConfigurationData) { this.latestConfigurationData = latestConfigurationData; this.cacheManagerName = cacheManagerName; }