예제 #1
0
        public TCacheItem Get(string nodeId, string key, DateTime ifModifySince)
        {
            CacheManager man = _cacheMans.GetCacheManager(nodeId);

            CacheItem ci = null;

            try
            {
                ci = man.Get(key);
            }
            catch (ItemNotFoundException)
            {
                throw new CacheItemNotFoundException();
            }

            if (ifModifySince != DateTime.MinValue)
            {
                long span = (long)(ci.ItemTime - ifModifySince).TotalSeconds;
                if (span <= 0)
                {
                    //Content not modify since the specify time
                    throw new CacheItemNotModifiedException(ci.ItemTime);
                }
            }

            //deserialize data
            object     val  = DataSerialize.Deserialize(ci.Content, (CacheDataType)ci.Properties);
            TCacheItem item = new TCacheItem(ci.Key, val, ci.ItemTime);

            return(item);
        }
예제 #2
0
        public TCacheItem[] MultiGet(string nodeId, string[] keys)
        {
            if (keys == null || keys.Length == 0)
            {
                throw new ArgumentNullException("keys");
            }

            CacheManager      man   = _cacheMans.GetCacheManager(nodeId);
            List <TCacheItem> items = new List <TCacheItem>();

            foreach (string key in keys)
            {
                try
                {
                    CacheItem ci = man.Get(key);

                    //deserialize data
                    object     val  = DataSerialize.Deserialize(ci.Content, (CacheDataType)ci.Properties);
                    TCacheItem item = new TCacheItem(ci.Key, val, ci.ItemTime);
                    items.Add(item);
                }
                catch (ItemNotFoundException)
                {
                    //ignore not found item(s)
                }
            }

            return(items.ToArray());
        }
예제 #3
0
        public void Add(string nodeId, TCacheItem item, int expirationSecond, bool absExpire)
        {
            CacheManager man = _cacheMans.GetCacheManager(nodeId);

            //serialize data
            byte[]        data;
            CacheDataType dataType;

            DataSerialize.Serialize(item.Value, out data, out dataType);

            CacheItem ci = new CacheItem(item.Key, data, item.ItemTime, (int)dataType);

            man.Set(ci, expirationSecond, absExpire);
        }