一.如果用官方提供的方法,在web.config里面配置好了各个参数和服务器IP。如下图:
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="enyim.com"> <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching"/> </sectionGroup> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> <enyim.com> <memcached protocol="Text"> <servers> <add address="127.0.0.1" port="11211" /> <add address="127.0.0.1" port="11212" /> <add address="127.0.0.1" port="11213" /> <add address="127.0.0.1" port="11214" /> </servers> <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:05" deadTimeout="00:02:00" /> </memcached> </enyim.com> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> </configuration>
则使用该通用类即可,组件自动调用web.config里面的配置。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif?x-oss-process=image/resize,w_1400/format,webp)
二.如果不想在web.config配置,那就使用下面的通用类。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif?x-oss-process=image/resize,w_1400/format,webp)