1,Why Memcached
On 1.1 web servers, the number of requests received by iis is limited. When the traffic volume is large, the Website access will encounter a bottleneck, the processing method is to use an extra server to distribute requests (clusters) and publish a public ip address.
1.2 When the traffic volume reaches, requests are distributed through three servers, and each server undertakes requests. When a user logs on, how to share login information becomes a problem that needs to be solved (for example, storing login information in the database may cause poor performance ).Distributed cacheApplication scenarios.
2,MemcachedBasic Introduction
2.1 key MAX: 255 bytes, value MAX: 1 m, {key: key1, value: 123}
3Use Memcache in Windows
3.1 download memcache: www.code.jellycan.com/Memcache
3.2 installation service: cmd---Memcached.exe-d install
3.3 start service: cmd---Memcached.exe-d start (restart, stop off)
3.4 check whether the service is started: connect to the Memcache Console: telnet 127.0.0.1 11211, press enter, and enter the command stats to check the current service status.
3.5 uninstall memcached.exe-d uninstall
Problem: if the program cannot be started, solution: Download MSVCR71.dll and install it.
3.6 add, delete, modify, query, and input commands
3.6.1 add keyname 0 0 5 Press ENTER // The first 0 is a number, and the second is the expiration time, in seconds. 0 represents an unlimited period, and 5 represents the value length. For example, if the keyname exists, no operation is performed.
12345 // value content
3.6.2 get keyname // get the value of the corresponding value
3.6.3 delete keyname // delete
3.6.4 set keyname 0 0 5 Press ENTER // if not, add it. If yes, update it.
12345
3,C #Perform the following operations on memcache:
4,Microsoft cache Method
Demo
Business logic layer:
Interface: ICacheManager
Get( Set( key, Set( key, value, Remove( }
CacheFactory class:
ICacheManager _instance = m_LockObj = (_instance == (_instance == cacheType = ConfigurationSettings.AppSettings[ (cacheType == _instance = _instance = }
MemCachedManager class:
m_CacheManager = MemcachedClient.GetInstance( Set( key, Set( key, value, Get( Remove( }
MsCacheManager class:
m_CacheManager = BaseCacheDAL( Get( Set( key, m_CacheManager.SetCache(key, value, Set( key, value, Remove( }
Call:
DataTable GetCarPList( dt = cacheManger.Get(CacheKey.GetCarPList_Key()) (dt == sql = .Format( dt = SqlHelper.ExecuteDataTable(com.Model.Base.DataBaseEnum.ruanmou, sql, CommandType.Text, cacheManger.Set(CacheKey.GetCarPList_Key(), dt, }
Important node configurations of web. config:
<appSettings> <add key= value=/> <!--<add key= value=/>--> </appSettings>
<configSections> <section name= type=/> <section name= type=/> <section name= type=/> <section name= type=/> </configSections>
<cachingConfiguration defaultCacheManager=> <cacheManagers> <add expirationPollFrequencyInSeconds= maximumElementsInCacheBeforeScavenging= numberToRemoveWhenScavenging= backingStoreName= type= name=/> </cacheManagers> <backingStores> <add encryptionProviderName= type= name=/> </backingStores> </cachingConfiguration> <enterpriseLibrary.ConfigurationSource selectedSource=> <sources> <add name= type=/> </sources> </enterpriseLibrary.ConfigurationSource> <memcachedgarden> <add key= value=/> </memcachedgarden>