Esempio n. 1
0
 /// <summary>
 /// Adds an item to the cache.
 /// </summary>
 /// <param name="key">The key for the item.</param>
 /// <param name="val">The item to add.</param>
 public void Add(
     string key,
     object val)
 {
     CacheItem item = new CacheItem(val, this.GetExpireTime());
     this.hash.Add(key, item);
     #if (CACHE_TRACE)
     LogManager.GetCurrentClassLogger().Debug(
     debugMessage => debugMessage("Item Added: {0} : {1}", key, val.ToString());
     #endif
 }
Esempio n. 2
0
        /// <summary>
        /// Updates the expire time of the given item if the cache is 
        /// <b>RELATIVE_EXPIRATION</b> and keep-alive is on.
        /// </summary>
        /// <param name="item">The <b>CacheItem</b> to update the expire time for.</param>
        private void UpdateExpireTime(
            CacheItem item)
        {
            //  the item's expire time can only be updated if the cache is set
            //  for relative expiration and to keep items alive when used
            if ((this.cacheType == CacheType.RELATIVE_EXPIRATION) && this.keepAlive) {
                DateTime expireTime = this.GetExpireTime();

                //  see if there is a drop dead time specified
                if (this.dropDeadTime != NULL_TIMESPAN) {
                    //  calculate the drop dead time based on the time the item was added
                    DateTime dropDeadTime = item.AddedAt;
                    dropDeadTime = dropDeadTime.Add(this.dropDeadTime);
                    //  if the drop dead time is sooner than the extended expire time,
                    //  use the drop dead time instead
                    if (dropDeadTime < expireTime) {
                        expireTime = dropDeadTime;
                    }
                }

                //  update the item's expire time
                item.ExpiresAt = expireTime;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Gets or sets the value of an item in the cache with the given key.
 /// </summary>
 public object this[string key]
 {
     get { return this.Get(key); }
     set
     {
         CacheItem item = new CacheItem(value, this.GetExpireTime());
         this.hash[key] = item;
     }
 }