Example #1
0
        public static void Add(string key, object val, DateTime absExpirationTime)
        {
            int expirationSecond = 0;

            if (absExpirationTime > DateTime.MinValue)
            {
                if (absExpirationTime < DateTime.Now)
                {
                    return;
                }

                double totalSeconds = (absExpirationTime - DateTime.Now).TotalSeconds;
                if (totalSeconds > int.MaxValue)
                {
                    expirationSecond = int.MaxValue;
                }
                else
                {
                    expirationSecond = (int)totalSeconds;
                }
            }
            Proxy.Add(
                NonPersistentNodesList.GetServerEndPoint(key),
                new TCacheItem(key, val, TCacheNP.NoItemTime),
                expirationSecond, true);
        }
Example #2
0
 /// <summary>
 /// Add or update a cache item
 /// </summary>
 public static void Add(string key, object val, TimeSpan expirationTime)
 {
     Proxy.Add(
         NonPersistentNodesList.GetServerEndPoint(key),
         new TCacheItem(key, val, TCacheNP.NoItemTime),
         (int)expirationTime.TotalSeconds, false);
 }
Example #3
0
        /// <summary>
        /// Get a cache item
        /// </summary>
        public static TCacheItem GetItem(string key)
        {
            //NOTE::
            //If the specify block does not exist, this method will return NULL

            try
            {
                return(Proxy.Get(
                           NonPersistentNodesList.GetServerEndPoint(key),
                           key, DateTime.MinValue));
            }
            catch (CacheItemNotFoundException)
            {
                return(null);
            }
        }
Example #4
0
        public static TCacheItem[] MultiGet(string[] keys)
        {
            //divide keys into groups
            List <NodeGroup> groups = new List <NodeGroup>();

            foreach (string key in keys)
            {
                string endPoint = NonPersistentNodesList.GetServerEndPoint(key);

                NodeGroup existGroup = null;
                foreach (NodeGroup group in groups)
                {
                    if (group.EndPoint == endPoint)
                    {
                        existGroup = group;
                        break;
                    }
                }

                if (existGroup == null)
                {
                    NodeGroup newGroup = new NodeGroup(endPoint);
                    newGroup.AddKey(key);
                    groups.Add(newGroup);
                }
                else
                {
                    existGroup.AddKey(key);
                }
            }

            //get items
            List <TCacheItem> items = new List <TCacheItem>(keys.Length);

            foreach (NodeGroup group in groups)
            {
                TCacheItem[] ci = Proxy.MultiGet(group.EndPoint, group.Keys);
                items.AddRange(ci);
            }

            return(items.ToArray());
        }
Example #5
0
 /// <summary>
 /// Remove a cache item
 /// </summary>
 public static void Remove(string key)
 {
     Proxy.Remove(
         NonPersistentNodesList.GetServerEndPoint(key),
         key);
 }