欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# memcached缓存使用实例代码

程序员文章站 2024-02-22 20:14:34
复制代码 代码如下:public interface icachestrategy    {    &...

复制代码 代码如下:

public interface icachestrategy
    {
        /// <summary>
        /// 添加数据到缓存
        /// </summary>
        /// <param name="objid">缓存名称</param>
        /// <param name="o">缓存内容</param>
        /// <param name="second">缓存时间(秒)</param>
        void add(string objid, object o, int second);

        /// <summary>
        /// 添加数据到缓存 (依赖其它缓存)
        /// </summary>
        /// <param name="objid">缓存名称</param>
        /// <param name="o">缓存内容</param>
        /// <param name="second">缓存时间(秒)</param>
        /// <param name="dependkey">依赖缓存名称数组</param>
        void addcachedepend(string objid, object o, int second, string[] dependkey);

        /// <summary>
        /// 添加数据到缓存 (依赖文件)
        /// </summary>
        /// <param name="objid">缓存名称</param>
        /// <param name="o">缓存内容</param>
        /// <param name="second">缓存时间(秒)</param>
        /// <param name="files">依赖缓存名称文件名数组</param>
        void addfiledepend(string objid, object o, int second, string[] files);

        /// <summary>
        /// 删除指定缓存
        /// </summary>
        /// <param name="objid"></param>
        void removecache(string objid);

        /// <summary>
        /// 删除所有缓存
        /// </summary>
        void removecacheall();

        /// <summary>
        /// 删除匹配到的缓存
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        void removecacheregex(string pattern);

        /// <summary>
        /// 获取所有缓存键
        /// </summary>
        /// <returns></returns>
        ilist<string> getcachekeys();

        /// <summary>
        /// 搜索 匹配到的缓存
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        ilist<string> searchcacheregex(string pattern);

        /// <summary>
        /// 获得缓存数据
        /// </summary>
        /// <param name="objid"></param>
        /// <returns></returns>
        object getcachedata(string objid);

        /// <summary>
        /// 判断此缓存是否有效
        /// </summary>
        /// <param name="objid"></param>
        /// <returns></returns>
        bool hascache(string objid);
    }