热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Memcached缓存帮助类

.NETMemcached分布式缓存帮助类1usingMemcached.ClientLibrary;2usingSystem;3usingSy

.NET Memcached分布式缓存帮助类

  1 using Memcached.ClientLibrary;
  2 using System;
  3 using System.Collections;
  4 using System.Collections.Generic;
  5 using System.Configuration;
  6 using System.Linq;
  7 using System.Text;
  8 
  9 namespace Components.Helper
 10 {
 11     /// 分布式缓存Memcach帮助类
 12     public class MemcachHelper
 13     {
 14         private static MemcachedClient _client;
 15         /// 默认缓存时间(默认20分钟)
 16         public static int DefaultCacheTime = (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DefaultCacheTime"]) ? Convert.ToInt32(ConfigurationManager.AppSettings["DefaultCacheTime"]) : 1200000);
 17 
 18         /// 
 19         /// 是否启用分布式缓存
 20         /// 
 21         public static bool IsEnableScatteredCache = (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["IsEnableScatteredCache"]) ? Convert.ToBoolean(ConfigurationManager.AppSettings["IsEnableScatteredCache"]) : true);
 22         static MemcachHelper()
 23         {
 24             string[] serverlist = (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["Memcached.ServerList"]) ? ConfigurationManager.AppSettings["Memcached.ServerList"].Split(',') : null);
 25 
 26             if (null == serverlist)
 27             {
 28                 serverlist = new string[] { "127.0.0.1:11211" };
 29             }
 30 
 31             SockIOPool pool = SockIOPool.GetInstance("First");
 32             pool.SetServers(serverlist);
 33             pool.Initialize();
 34 
 35             //初始化
 36             _client = new MemcachedClient();
 37             _client.PoolName = "First";
 38             _client.EnableCompression = false;
 39         }
 40 
 41         #region Add
 42         public static bool Add(string key, object value)
 43         {
 44             DateTime m_expiryTime = DateTime.Now.AddMilliseconds(DefaultCacheTime);
 45             return _client.Add(key, value, m_expiryTime);
 46         }
 47         public static bool Add(string key, object value, DateTime expiry)
 48         {
 49             return _client.Add(key, value, expiry);
 50         }
 51         public static bool Add(string key, object value, int hashCode)
 52         {
 53             return _client.Add(key, value, hashCode);
 54         }
 55         public static bool Add(string key, object value, DateTime expiry, int hashCode)
 56         {
 57             return _client.Add(key, value, expiry, hashCode);
 58         }
 59         #endregion
 60 
 61         #region Delete
 62         /// 删除缓存
 63         /// 
 64         /// 
 65         public static bool Delete(string key)
 66         {
 67             return _client.Delete(key);
 68         }
 69 
 70         /// 删除缓存
 71         /// 
 72         /// 
 73         /// 
 74         public static bool Delete(string key, DateTime expiry)
 75         {
 76             return _client.Delete(key, expiry);
 77         }
 78 
 79         /// 删除缓存
 80         /// 
 81         /// 
 82         /// 
 83         /// 
 84         public static bool Delete(string key, object hashCode, DateTime expiry)
 85         {
 86             return _client.Delete(key, hashCode, expiry);
 87         }
 88 
 89         #endregion
 90 
 91         #region Get
 92         /// 获取缓存
 93         /// 
 94         /// 
 95         public static object Get(string key)
 96         {
 97             return _client.Get(key);
 98         }
 99         /// 获取缓存
100         /// 
101         /// 
102         /// 
103         public static object Get(string key, int hashCode)
104         {
105             return _client.Get(key, hashCode);
106         }
107         /// 获取缓存
108         /// 
109         /// 
110         /// 
111         /// 
112         public static object Get(string key, object hashCode, bool asString)
113         {
114             return _client.Get(key, hashCode, asString);
115         }
116         #endregion
117 
118         #region Replace
119         /// 
120         /// 替换更新
121         /// 
122         /// 
123         /// 
124         /// 
125         public static bool Replace(string key, object value)
126         {
127             return _client.Replace(key, value);
128         }
129         /// 
130         /// 替换更新
131         /// 
132         /// 
133         /// 
134         /// 
135         /// 
136         public static bool Replace(string key, object value, DateTime expiry)
137         {
138             return _client.Replace(key, value, expiry);
139         }
140         /// 
141         /// 替换更新
142         /// 
143         /// 
144         /// 
145         /// 
146         /// 
147         public static bool Replace(string key, object value, int hashCode)
148         {
149             return _client.Replace(key, value, hashCode);
150         }
151         /// 
152         /// 替换更新
153         /// 
154         /// 
155         /// 
156         /// 
157         /// 
158         /// 
159         public static bool Replace(string key, object value, DateTime expiry, int hashCode)
160         {
161             return _client.Replace(key, value, expiry, hashCode);
162         }
163         #endregion
164 
165         #region Set
166         public static bool Set(string key, object value)
167         {
168             return _client.Set(key, value);
169         }
170         public static bool Set(string key, object value, DateTime expiry)
171         {
172             return _client.Set(key, value, expiry);
173         }
174         public static bool Set(string key, object value, int hashCode)
175         {
176             return _client.Set(key, value, hashCode);
177         }
178         public static bool Set(string key, object value, DateTime expiry, int hashCode)
179         {
180             return _client.Set(key, value, expiry, hashCode);
181         }
182         #endregion
183 
184         #region Stats
185         public static Hashtable Stats()
186         {
187             return _client.Stats();
188         }
189 
190         public static Hashtable Stats(ArrayList servers)
191         {
192             return _client.Stats(servers);
193         }
194         #endregion
195 
196         /// 判断指定Key的缓存是否存在
197         /// 
198         /// 
199         public static bool KeyExists(string key)
200         {
201             return _client.KeyExists(key);
202         }
203 
204         /// 
205         /// 移除缓存,针对空间
206         /// 
207         /// 
208         public static void RemoveRegionCache(string regionName)
209         {
210 
211         }
212     }
213 }
MemcachHelper

 


推荐阅读
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 第四章高阶函数(参数传递、高阶函数、lambda表达式)(python进阶)的讲解和应用
    本文主要讲解了第四章高阶函数(参数传递、高阶函数、lambda表达式)的相关知识,包括函数参数传递机制和赋值机制、引用传递的概念和应用、默认参数的定义和使用等内容。同时介绍了高阶函数和lambda表达式的概念,并给出了一些实例代码进行演示。对于想要进一步提升python编程能力的读者来说,本文将是一个不错的学习资料。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • 本文讨论了编写可保护的代码的重要性,包括提高代码的可读性、可调试性和直观性。同时介绍了优化代码的方法,如代码格式化、解释函数和提炼函数等。还提到了一些常见的坏代码味道,如不规范的命名、重复代码、过长的函数和参数列表等。最后,介绍了如何处理数据泥团和进行函数重构,以提高代码质量和可维护性。 ... [详细]
author-avatar
我财我乐汽车869
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有