예제 #1
0
        public bool InsertWithReleaseLock(string key, object value, object lockHandle, Expiration expiration)
        {
            if (!Loaded)
                return false;

            if (value is byte[])
                value = new ByteArray((byte[])value);

            CacheItem item = CreateCacheItem(value, expiration);
            LockHandle handle = lockHandle as LockHandle;
            try
            {
                cache.Insert(key, item, handle, true);
                return true;
            }
            catch(Exception ex)
            {
                FileBasedTraceProvider.Current.WriteTrace(TraceSeverity.Exception, "Could not add item to cache due to exception: {0}", ex.Message);
                return false;
            }
        }
예제 #2
0
        CacheItem CreateCacheItem(object value, Expiration expiration)
        {
            DateTime absolute = Cache.NoAbsoluteExpiration;
            TimeSpan sliding = Cache.NoSlidingExpiration;

            if (expiration != null)
            {
                switch (expiration.ExpirationType)
                {
                    case ExpirationType.Absolute:
                        absolute = DateTime.Now.AddMinutes(expiration.Duration);
                        break;

                    case ExpirationType.Sliding:
                        sliding = TimeSpan.FromMinutes(expiration.Duration);
                        break;
                }
            }

            CacheItem item = new CacheItem(value);
            item.AbsoluteExpiration = absolute;
            item.SlidingExpiration = sliding;
            return item;
        }
예제 #3
0
        public bool Insert(string key, object value, Expiration expiration)
        {
            CacheItem cacheItem = CreateCacheItem(value, expiration);

            if (!Loaded)
                return false;
            else
            {
                cache.Insert(key, cacheItem);
                return true;
            }
        }