예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
 public LayeredCache(String name, LayeredCachePolicy policy)
     : this(
         name,
         (policy != null ? policy.Level1CacheName : null),
         (policy != null ? policy.Level2CacheName : null))
 {
     this.policy = policy;
 }
예제 #4
0
        public LayeredCache(String name, LayeredCachePolicy policy)
            : this(name, policy?.Level1CacheName, policy?.Level2CacheName)
        {
            this.policy = policy ?? throw new ArgumentNullException(nameof(policy));

            if (policy.InvalidateLevel1OnLevel2Upsert)
            {
                if (this.level1 is NoCache)
                {
                    policy.InvalidateLevel1OnLevel2Upsert = false;
                }
                else
                {
                    level1Notifier = CacheManager.GetAssociatedNotifier(this.level1);
                    if (level1Notifier == null)
                    {
                        throw new ApplicationException(
                                  "InvalidateLevel1OnLevel2Upsert requires level1 cache to have SyncProvider defined in policy: level1CacheName=" +
                                  policy.Level1CacheName);
                    }
                }
            }
        }
예제 #5
0
 public LayeredCache(String name, LayeredCachePolicy policy)
     : this(name, policy?.Level1CacheName, policy?.Level2CacheName)
 {
     this.policy = policy;
 }