/// <summary>
 /// Initialize a new instance of the <see cref="CacheManagerData"/> class.
 /// </summary>
 /// <param name="name">
 /// The name of the <see cref="CacheManagerData"/>.
 /// </param>
 /// <param name="expirationPollFrequencyInSeconds">
 /// Frequency in seconds of expiration polling cycle
 /// </param>
 /// <param name="maximumElementsInCacheBeforeScavenging">
 /// Maximum number of items in cache before an add causes scavenging to take place
 /// </param>
 /// <param name="numberToRemoveWhenScavenging">
 /// Number of items to remove from cache when scavenging
 /// </param>
 /// <param name="cacheStorage">
 /// CacheStorageData object from configuration describing how data is stored
 /// in the cache.
 /// </param>
 public CacheManagerData(string name, int expirationPollFrequencyInSeconds, int maximumElementsInCacheBeforeScavenging, int numberToRemoveWhenScavenging, CacheStorageData cacheStorage) : base(name)
 {
     this.expirationPollFrequencyInSeconds       = expirationPollFrequencyInSeconds;
     this.maximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavenging;
     this.numberToRemoveWhenScavenging           = numberToRemoveWhenScavenging;
     this.cacheStorage = cacheStorage;
 }
        public void Setup()
        {
            CacheStorageData cacheStorageData = new CacheStorageData("Null Storage", typeof(NullBackingStore));
            CacheManagerData cacheManagerData = new CacheManagerData("Default Cache Manager", 10, 10, 10, cacheStorageData.Name);
            
            CacheManagerSettings settings = new CacheManagerSettings();
            settings.CacheManagers.Add(cacheManagerData);
            settings.BackingStores.Add(cacheStorageData);

            settings.DefaultCacheManager = cacheManagerData.Name;

            registrations = settings.GetRegistrations(null);
        }
 public System.Configuration.ConfigurationSection GetSection(string sectionName)
 {
     if (sectionName.Equals("cachingConfiguration", StringComparison.CurrentCulture))
     {
         CacheManagerSettings settings = new CacheManagerSettings();
         settings.DefaultCacheManager = "Default Cache Manager";
         CacheManagerData data = new CacheManagerData("Default Cache Manager", 60, 1000, 10, "inMemory");
         settings.CacheManagers.Add(data);
         CacheStorageData storageData = new CacheStorageData("inMemory", typeof(NullBackingStore));
         settings.BackingStores.Add(storageData);
         return settings;
     }
     return null;
 }
        public void Setup()
        {
            configurationSource = new ConfigurationSourceUpdatable();
            cacheSettings = new CacheManagerSettings();

            configurationSource.Add(CacheManagerSettings.SectionName, cacheSettings);

            cacheStorageData = new CacheStorageData("Null Storage", typeof(NullBackingStore));
            cacheManagerData = new CacheManagerData("Default Cache Manager", 10, 10, 10, cacheStorageData.Name);
            
            CacheManagerSettings settings = new CacheManagerSettings();
            cacheSettings.CacheManagers.Add(cacheManagerData);
            cacheSettings.BackingStores.Add(cacheStorageData);
            cacheSettings.DefaultCacheManager = cacheManagerData.Name;

            UnityContainer container = new UnityContainer();
            configurator = new UnityContainerConfigurator(container);
            serviceLcoator = new UnityServiceLocator(container);
            EnterpriseLibraryContainer.ConfigureContainer(configurator, configurationSource);
        }
Exemple #5
0
 /// <summary>
 /// Initialize a new instance of the <see cref="CacheManagerData"/> class.
 /// </summary>
 /// <param name="name">
 /// The name of the <see cref="CacheManagerData"/>.
 /// </param>
 /// <param name="expirationPollFrequencyInSeconds">
 /// Frequency in seconds of expiration polling cycle
 /// </param>
 /// <param name="maximumElementsInCacheBeforeScavenging">
 /// Maximum number of items in cache before an add causes scavenging to take place
 /// </param>
 /// <param name="numberToRemoveWhenScavenging">
 /// Number of items to remove from cache when scavenging
 /// </param>
 /// <param name="cacheStorage">
 /// CacheStorageData object from configuration describing how data is stored 
 /// in the cache.
 /// </param>
 public CacheManagerData(string name, int expirationPollFrequencyInSeconds, int maximumElementsInCacheBeforeScavenging, int numberToRemoveWhenScavenging, CacheStorageData cacheStorage)
     : base(name)
 {
     this.expirationPollFrequencyInSeconds = expirationPollFrequencyInSeconds;
     this.maximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavenging;
     this.numberToRemoveWhenScavenging = numberToRemoveWhenScavenging;
     this.cacheStorage = cacheStorage;
 }
            public ICachingConfiguration StoreInMemory()
            {
                var nullBackingStore = CachingSettings.BackingStores.Where(x => x.Type == typeof(NullBackingStore)).FirstOrDefault();
                if (nullBackingStore == null)
                {
                    nullBackingStore = new CacheStorageData("Null Backing Store", typeof(NullBackingStore));
                    CachingSettings.BackingStores.Add(nullBackingStore);
                }

                return StoreInSharedBackingStore(nullBackingStore.Name);
            }
 public TestCachingConfigurationView(CacheStorageData data, ConfigurationContext context)
     : base(context)
 {
     this.data = data;
 }
        public void Setup()
        {
            CacheStorageData storeData = new CacheStorageData("cache store",typeof(BackingStoreWithoutDefaultCtor));

            settings = new CacheManagerSettings();
            settings.BackingStores.Add(storeData);
        }
        public void CacheManagerIsSingleton()
        {
            CacheStorageData data = new CacheStorageData("storage", typeof(NullBackingStore));
            settings.BackingStores.Add(data);

            CacheManagerData managerData = new CacheManagerData("name", 300, 200, 100, "storage");
            settings.CacheManagers.Add(managerData);

            IServiceLocator container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

            CacheManager createdObject1 = (CacheManager)container.GetInstance<ICacheManager>("name");
            CacheManager createdObject2 = (CacheManager)container.GetInstance<ICacheManager>("name");

            Assert.IsNotNull(createdObject1);
            Assert.AreSame(createdObject1, createdObject2);
        }
        public void CanCreateCacheManager()
        {
            CacheStorageData data = new CacheStorageData("storage", typeof(NullBackingStore));
            settings.BackingStores.Add(data);

            CacheManagerData managerData = new CacheManagerData("name", 300, 200, 100, "storage");
            settings.CacheManagers.Add(managerData);

            IServiceLocator container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

            CacheManager createdObject = (CacheManager)container.GetInstance<ICacheManager>("name");

            Assert.IsNotNull(createdObject);

            // does it work?
            object value = new object();
            createdObject.Add("key", value);
            Assert.AreSame(value, createdObject.GetData("key"));
        }
 /// <summary>
 /// Adds a <see cref="CacheStorageData"/> to the <see cref="CacheManagerSettings"/> as well as adds a reference to the <see cref="CacheManager"/> instance currently being configured.
 /// </summary>
 /// <param name="backingStore">The <see cref="CacheStorageData"/> that should be added to configuration.</param>
 protected void AddBackingStoreToCachingConfigurationAndCurrentCacheManager(CacheStorageData backingStore)
 {
     currentBackingStore = backingStore;
     contextExtension.CachingSettings.BackingStores.Add(backingStore);
     contextExtension.CacheManager.CacheStorage = backingStore.Name;
 }