标题:本人开发的缓存类
只看楼主
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib.FileHelper
{
    public class FileForBase
    {
        string _trueFilePath;
        /// <summary>
        /// 当前文件的绝对路径(c:\\abc.txt)
        /// </summary>
        public string TrueFilePath
        {
            get { return _trueFilePath; }
            set { _trueFilePath = value; }
        }
        Encoding _encode;
        /// <summary>
        /// 读取或者写入时候的编码
        /// </summary>
        public Encoding Encode
        {
            get { return _encode; }
            set { _encode = value; }
        }
    }
}

59ita点com(我就爱TA)
2012-10-17 12:30
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
namespace ITA.Base.EntLib.FileHelper
{
    public class FileHelper : CacheDataHelper,IDataHelper
    {


        #region IDataHelper 成员

        public object GetItem(IHelperPara NamespaceClassnameAndPara, System.Collections.Hashtable ht, object forbase)
        {

            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.ClearExdateCache();
            CacheItem item = cache.GetItem(NamespaceClassnameAndPara, cache.DataDoing(new DataDelegate(GetDataByDataBase), forbase));
            return item.Data;

            //throw new NotImplementedException();
        }

        #endregion
        object GetDataByDataBase(object forbase)
        {
            FileForBase fb = (FileForBase)forbase;
            string t = ITA_File.ReadFile(fb.TrueFilePath, PathType.AbsolutePath, fb.Encode);
            return t;
        }



        #region IDataHelper 成员


        public object GetItem(IHelperPara NamespaceClassnameAndPara, System.Collections.Hashtable ht)
        {
            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.ClearExdateCache();
            CacheItem item = cache.GetItem(NamespaceClassnameAndPara, cache.DataDoing(new DataDelegate(GetDataByDataBase), NamespaceClassnameAndPara.Para));
            return item.Data;
        }

        #endregion
    }
}

59ita点com(我就爱TA)
2012-10-17 12:30
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib.FileHelper
{
    /// <summary>
    /// 用于数据缓存的类,代表key
    /// </summary>
    public class FileHelperPara :HelperPara, IHelperPara
    {
        FileForBase _Para;
        /// <summary>
        /// 数据路径(FileForBase类型)
        /// </summary>
        public object Para
        {
            get { return _Para; }
            set { _Para = (FileForBase)value; }
        }



    }
}

59ita点com(我就爱TA)
2012-10-17 12:31
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
namespace ITA.Base.EntLib.FileHelper
{
    public class XMLForBase
    {
        string _trueFilePath;
        /// <summary>
        /// 当前文件的绝对路径(c:\\abc.txt),是委托的参数之一
        /// </summary>
        public string TrueFilePath
        {
            get { return _trueFilePath; }
            set { _trueFilePath = value; }
        }
        object _ClassName;
        /// <summary>
        /// 读取或者写入时候的类(new 后的类)
        /// </summary>
        public object ClassName
        {
            get { return _ClassName; }
            set { _ClassName = value; }
        }
        WriteToXML _WriteToXML;
        /// <summary>
        /// 委托的事件 使用new WriteToXML(方法)
        /// </summary>
        public WriteToXML WriteToXML
        {
            get { return _WriteToXML; }
            set { _WriteToXML = value; }
        }
        string _idormd5;
        /// <summary>
        /// ID或者md5码,是委托的参数之一
        /// </summary>
        public string IdOrMd5
        {
            get { return _idormd5; }
            set { _idormd5 = value; }
        }
    }
}

59ita点com(我就爱TA)
2012-10-17 12:31
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib.FileHelper
{
    public class XMLHelper : CacheDataHelper,IDataHelper
    {


        #region IDataHelper 成员

        public object GetItem(IHelperPara NamespaceClassnameAndPara, System.Collections.Hashtable ht, object forbase)
        {

            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.ClearExdateCache();
            CacheItem item = cache.GetItem(NamespaceClassnameAndPara, cache.DataDoing(new DataDelegate(GetDataByDataBase), forbase));
            return item.Data;

            //throw new NotImplementedException();
        }

        #endregion
        object GetDataByDataBase(object forbase)
        {
            XMLForBase fb = (XMLForBase)forbase;
            if (ITA_File.FindFile(fb.TrueFilePath, PathType.AbsolutePath))
            {
                ITA.Base.DataHelp.XMLToObject(fb.TrueFilePath, fb.ClassName);
            }
            else
            {
                WXml(fb.WriteToXML, fb.IdOrMd5, fb.TrueFilePath,fb.ClassName);
                ITA.Base.DataHelp.XMLToObject(fb.TrueFilePath, fb.ClassName);
            }

            return fb.ClassName;
        }
        void WXml(WriteToXML wtxml, string idormd5, string path,object classname)
        {
            wtxml(idormd5, path,classname);
        }



        #region IDataHelper 成员


        public object GetItem(IHelperPara NamespaceClassnameAndPara, System.Collections.Hashtable ht)
        {
            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.ClearExdateCache();
            CacheItem item = cache.GetItem(NamespaceClassnameAndPara, cache.DataDoing(new DataDelegate(GetDataByDataBase), NamespaceClassnameAndPara.Para));
            return item.Data;
        }

        #endregion
    }
}

59ita点com(我就爱TA)
2012-10-17 12:31
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib.FileHelper
{
    /// <summary>
    /// 用于数据缓存的类,代表key
    /// </summary>
    public class XMLHelperPara :HelperPara, IHelperPara
    {
        XMLForBase _Para;
        /// <summary>
        /// 数据路径(FileForBase类型)
        /// </summary>
        public object Para
        {
            get { return _Para; }
            set { _Para = (XMLForBase)value; }
        }



    }
}

59ita点com(我就爱TA)
2012-10-17 12:32
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib
{
    public class CacheDataHelper
    {
        static int _count = string.IsNullOrEmpty(ConfigurationManager.AppSettings["CacheCount"]) ? 50 : int.Parse(ConfigurationManager.AppSettings["CacheCount"]);

        protected object GetItem<T>(IHelperPara NamespaceClassnameAndPara, Hashtable ht, object forbase ,DataDelegate methodes) where T : new()
        {
            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            CacheItem item = cache.GetItem(NamespaceClassnameAndPara, cache.DataDoing(methodes, forbase));
            return item.Data;
            ///cache.Dispose();
        }
        /// <summary>
        /// 添加一个缓存
        /// </summary>
        /// <param name="ht"></param>
        /// <param name="NamespaceClassnameAndPara"></param>
        /// <param name="value"></param>
        /// <param name="priority"></param>
        /// <param name="dt"></param>
        public void ADDCache(Hashtable ht, IHelperPara NamespaceClassnameAndPara, object value, CacheItemPriority priority, DateTime dt)
        {
            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.ClearExdateCache();
            if (cache.Count >= _count)
            {
                cache.RemoveCacheByCacheItemPriority();
            }
            cache.Add(NamespaceClassnameAndPara, value, priority, dt);
        }
        /// <summary>
        /// 删除一个缓存
        /// </summary>
        /// <param name="ht"></param>
        /// <param name="key"></param>
        public void Remove(Hashtable ht, object key)
        {
            ICache cache = new ITA.Base.EntLib.Caching.Cache(ht);
            cache.Remove(key);
        }


    }
}

59ita点com(我就爱TA)
2012-10-17 12:32
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib
{
    public class HelperPara
    {
        string _nameSpace;
        /// <summary>
        /// 空间命名
        /// </summary>
        public string NameSpace
        {
            get { return _nameSpace; }
            set { _nameSpace = value; }
        }
        string _className;
        /// <summary>
        /// 类名
        /// </summary>
        public string ClassName
        {
            get { return _className; }
            set { _className = value; }
        }
        string _Mothed;
        /// <summary>
        /// 方法名
        /// </summary>
        public string Mothed
        {
            get { return _Mothed; }
            set { _Mothed = value; }
        }

    }
}

59ita点com(我就爱TA)
2012-10-17 12:33
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib
{
    /// <summary>
    /// 数据缓存操作接口(new DataHelper&lt;T&gt;(),T为类型/ new FileHelper()/new XMLHelper())
    /// </summary>
    public interface IDataHelper
    {
        //IHelperPara NamespaceClassnameAndPara { set; get; }
        //Hashtable HT { set; get; }
        //object ForBase { get; set; }

        /// <summary>
        /// 根据条件从缓存库中获取数据(数据库是返回IList&lt;T&gt; / 文件是返回string/xml返回类)[否决的]
        /// </summary>
        /// <typeparam name="T">返回的类</typeparam>
        /// <param name="NamespaceClassnameAndPara">保存在缓存库中的key</param>
        /// <param name="ht">缓存库</param>
        /// <param name="forbase">如果库中不存在,使用这些条件获取数据(类型:FileForBase/DataForBase/XMLForBase)</param>
        /// <returns></returns>
       // object GetItem(IHelperPara NamespaceClassnameAndPara, Hashtable ht, object forbase);
        /// <summary>
        /// 根据条件从缓存库中获取数据(数据库是返回IList&lt;T&gt; / 文件是返回string/xml返回类)
        /// </summary>
        /// <typeparam name="T">返回的类</typeparam>
        /// <param name="NamespaceClassnameAndPara">保存在缓存库中的key</param>
        /// <param name="ht">缓存库</param>
        /// <returns></returns>
        object GetItem(IHelperPara NamespaceClassnameAndPara, Hashtable ht);
        /// <summary>
        /// 添加一条缓存到缓存库
        /// </summary>
        /// <param name="ht">缓存库</param>
        /// <param name="NamespaceClassnameAndPara">保存在缓存库中的key</param>
        /// <param name="value"></param>
        /// <param name="priority">缓存的类型和等级</param>
        /// <param name="dt">过去时间</param>
        void ADDCache(Hashtable ht, IHelperPara NamespaceClassnameAndPara, object value, CacheItemPriority priority, DateTime dt);
        /// <summary>
        /// 删除一条缓存
        /// </summary>
        /// <param name="ht">缓存库</param>
        /// <param name="key">保存在缓存库中的key</param>
        void Remove(Hashtable ht, object key);
    }
}

59ita点com(我就爱TA)
2012-10-17 12:33
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
程序代码:
namespace ITA.Base.EntLib
{
    public interface IHelperPara
    {
        /// <summary>
        /// 空间命名
        /// </summary>
        string NameSpace
        {
            get;
            set;
        }
        /// <summary>
        /// 当前类名
        /// </summary>
        string ClassName
        {
            get;
            set;
        }
        /// <summary>
        /// 方法名
        /// </summary>
        string Mothed
        {
            get;
            set;
        }
        /// <summary>
        /// FileForBase/DataForBase/XMLForBase 类
        /// </summary>
        object Para
        {
            get;
            set;
        }
    }
}

59ita点com(我就爱TA)
2012-10-17 12:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-383411-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.391725 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved