Example #1
0
        public CacheMediumBase(string name, CacheCapacity capacity, ILoggerFacade logger)
        {
            this.logger = logger;

            if (this.logger != null)
            {
                this.logger.Log("Cache medium " + name + " instance is created.", Category.Info, Priority.Medium);
            }

            this.Capacity = capacity;

            this.name = name;
            this.algorithm = null;

            this.next = null;
            this.previous = null;

            this.algorithmData = new AlgorithmData();

            this.rwLock = new object();
        }
Example #2
0
        private void MoveCacheItem(ICacheMedium from, ICacheMedium to, CacheKey key, CacheValue value)
        {
            if (this.logger != null)
            {
                this.logger.Log("Move cache item: " + key.ToString() + " from " + from.CacheName + " to " + to.CacheName, Category.Info, Priority.Medium);
            }

            from.Remove(key);

            to.Set(key, value);
        }
Example #3
0
        private void ReplaceItemsIfNecessary(ICacheMedium medium)
        {
            CacheKey[] items = medium.Replace();

            if (items == null)
            {
                return;
            }

            ICacheMedium next = medium.Next();

            if (next != null)
            {
                foreach (CacheKey item in items)
                {
                    // set the cache item to next medium
                    next.Set(item, medium.Get(item));
                }
            }

            foreach (CacheKey item in items)
            {
                // remove the cache item from previous medium
                medium.Remove(item);
            }
        }