Exemplo n.º 1
0
        /// <summary>
        /// »ñÈ¡»º´æ¶ÔÏó
        /// </summary>
        /// <param name="key">»º´æ¼üÃû</param>
        /// <returns>·µ»Ø»º´æ¶ÔÏó</returns>
        public object Get(string key)
        {
            if (!cacheList.ContainsKey(key))
            {
                return(null);
            }
            CachedItem item = cacheList[key];

            return(DateTime.Now.IsBetween(item.StartTime, item.EndTime) ? item.CacheData : null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// »ñÈ¡»º´æ¶ÔÏó
        /// </summary>
        /// <param name="key">»º´æ¼üÃû</param>
        /// <returns>·µ»Ø»º´æ¶ÔÏó</returns>
        public T Get <T>(string key)
        {
            if (!cacheList.ContainsKey(key))
            {
                return(default(T));
            }
            CachedItem item = cacheList[key];

            return(DateTime.Now.IsBetween(item.StartTime, item.EndTime) ? (T)item.CacheData : default(T));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Ôö¼Ó»º´æÏîÄ¿
        /// </summary>
        /// <param name="key">»º´æ¼üÃû</param>
        /// <param name="obj">»º´æ¶ÔÏó</param>
        /// <param name="seconds">»º´æÃëÊý</param>
        public void Insert(string key, object obj, int seconds)
        {
            Remove(key);
            CachedItem item = new CachedItem();

            item.StartTime = DateTime.Now;
            item.EndTime   = DateTime.Now.AddSeconds(seconds * Factor);
            item.CacheData = obj;
            item.CacheType = obj.GetType().ToString();
            item.CacheKey  = key;
            cacheList.Add(key, item);
        }