码迷,mamicode.com
首页 > 系统相关 > 详细

cache

时间:2015-09-25 11:29:07      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
namespace WindowsFormsApplication1
{
        public class Caching
        {
            /// <summary>
            /// 缓存对象
            /// </summary>
            public static readonly Caching Cache = new Caching();
            private System.Collections.Hashtable _cache;

            private Caching()
            {
                _cache = new Hashtable();
            }
            /// <summary>
            /// 获取/设置缓存对象
            /// </summary>
            /// <param name="key">键值</param>
            /// <returns></returns>
            public object this[string key]
            {
                get
                {
                    //获取缓存对象
                    return (_cache[key]);
                }
                set
                {
                    if (_cache.Contains(key))
                    {
                        //缓存中已存在该键,先删除该键,然后设置新的键及对象
                        Remove(key);
                    }
                    //添加缓存对象
                    _cache.Add(key, value);
                }
            }
            /// <summary>
            /// 清除缓存中指定键对象
            /// </summary>
            /// <param name="key">键值</param>
            public void Remove(string key)
            {
                _cache.Remove(key);
            }
            /// <summary>
            /// 清除缓存中所有对象
            /// </summary>
            public void RemoveAll()
            {
                _cache.Clear();
            }
    }
}


cache

标签:

原文地址:http://my.oschina.net/u/2416019/blog/511010

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!