Esempio n. 1
0
        /// <summary>
        /// Creates a layered cache
        /// </summary>
        /// <param name="name"></param>
        /// <param name="level1CacheName">Name of first cache to check (e.g. in-memory cache), should be registered in CacheManager</param>
        /// <param name="level2CacheName">Name of fallback cache (e.g. distributed cache), should be registered in CacheManager</param>
        public LayeredCache(String name, String level1CacheName, String level2CacheName)
        {
            this.name = name;

            // ReSharper disable once LocalVariableHidesMember
            var level1 = CacheManager.GetCache(level1CacheName);

            if (level1 == null)
            {
                throw new ApplicationException("Cache is not registered: level1CacheName=" + level1CacheName);
            }

            // ReSharper disable once LocalVariableHidesMember
            var level2 = CacheManager.GetCache(level2CacheName);

            if (level2 == null)
            {
                throw new ApplicationException("Cache is not registered: level2CacheName=" + level2CacheName);
            }

            if (level2 == level1)
            {
                throw new ApplicationException(
                          string.Format("level2 must not be the same as level1, received {0}={1}, {2}={3}, which map to {4} and {5}",
                                        "level1CacheName", level1CacheName, "level2CacheName", level2CacheName, level1.Name, level2.Name));
            }

            this.level1 = level1;
            this.level2 = level2;

            this.policy = new LayeredCachePolicy {
                Level1CacheName = level1CacheName, Level2CacheName = level1CacheName
            };
            this.synchronizer = CacheSynchronizer.CreateCacheSynchronizer(this, this.policy?.SyncProvider);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a layered cache
        /// </summary>
        /// <param name="name"></param>
        /// <param name="level1">First cache to check (e.g. in-memory cache)</param>
        /// <param name="level2">Fallback cache (e.g. distributed cache)</param>
        public LayeredCache(String name, ICache level1, ICache level2)
        {
            this.name = name;

            if (level1 == null)
            {
                throw new ApplicationException("innerCache1 must not be null");
            }

            if (level2 == null)
            {
                throw new ApplicationException("innerCache2 must not be null");
            }

            if (level2 == level1)
            {
                throw new ApplicationException(
                          string.Format("Cache2 must not be the same as cache2, received {0}={1} and {2}={3}",
                                        "level1", level1.Name, "level2", level2.Name));
            }

            this.level1 = level1;
            this.level2 = level2;

            this.policy = new LayeredCachePolicy {
                Level1CacheName = level1.Name, Level2CacheName = level2.Name
            };
            this.synchronizer = CacheSynchronizer.CreateCacheSynchronizer(this, this.policy?.SyncProvider);
        }
Esempio n. 3
0
        public static CacheSynchronizer CreateCacheSynchronizer(ICache cache, string syncProviderName)
        {
            if (!String.IsNullOrEmpty(syncProviderName))
            {
                var notifications = CacheManager.GetNotifierForCache(cache.Name, syncProviderName);

                if (notifications != null)
                {
                    var synchronizer = new CacheSynchronizer(cache, notifications);
                    return(synchronizer);
                }
            }
            return(null);
        }
Esempio n. 4
0
        public static CacheSynchronizer CreateCacheSynchronizer(ICache cache, string syncProviderName)
        {
            if (string.IsNullOrEmpty(syncProviderName))
            {
                return(null);
            }

            var notifier = CacheManager.GetNotifier(syncProviderName);

            if (notifier == null)
            {
                return(null);
            }

            var synchronizer = new CacheSynchronizer(cache, notifier);

            return(synchronizer);
        }
Esempio n. 5
0
        public static CacheSynchronizer CreateCacheSynchronizer(ICache cache, string syncProviderName, bool invalidateOnStateChange)
        {
            if (string.IsNullOrEmpty(syncProviderName))
            {
                return(null);
            }

            var notifier = CacheManager.GetNotifier(syncProviderName);

            if (notifier == null)
            {
                return(null);
            }

            var synchronizer = new CacheSynchronizer(cache, notifier, invalidateOnStateChange);

            CacheManager.Associate(cache, notifier);

            return(synchronizer);
        }