In recent hands-on training when talking about the cache of this one, found himself a thorough enough understanding of the caching system, it will be attempted to use this time to sort out common caching mechanism and the corresponding software.
Speaking of the cache, I have to say memcached, born to solve the problem of cache.
First, what is the Memcached
memcached is a high performance, distributed memory cache-based servers. Normal action is, by the data cache back-end database, to reduce the pressure of the back-end database. Scalability and improve the response speed of the web application.
Two, memcached features
High performance as a cache server, has the following characteristics
- Simple protocol
- Libevent-based event processing
- RAM-based cache
- Distributed not communicate with each other
1, a simple protocol
Memcached simple protocol between the server and the client, the other does not rely on complex protocols with json xml or the like. But based on a simple line of text protocol. You can access data on a remote server via memcached telnet.
2. Based on the libevent event processing
libevent is a library that will function in the event linux processing functions packaged into a unified interface
This do not know, late familiar with the supplement
3. memory-based cache
To improve performance, memcached uses memory as the storage of data, so when the cache server after a power outage, the data will disappear, as its not like redis, does not support persistent data. When the memory reaches a certain value, it will be used prior to weed out the data cache LRU algorithm.
4. The mutual communication is not distributed
Although memcached distributed server, when the server does not communicate with each other between the individual, which is distributed by the client to achieve.
Three, Memcached operations on the data
Support for memcached memory key-value pairs, but can also set an expiration time. Do not set an expiration time, it will be removed in accordance with the policy of culling LRU data after reaching the memory capacity.
1, save data
set ( "key", "value", "Expiration Time")
the replace ( "key", "value", "Expiration Time")
the Add ( "key", "value", "Expiration Time")
This method is a little three the difference here is not to make a distinction.
2. Get the data
GET ( "key") takes out a key
GET ( "a key", "key two", "three key") takes out a plurality of values
3. Delete Data
delete ( "key", "blocking time")
where the second argument refers to block the specified time when removed, preventing the use of the same key to save the new data.
4. The plus and minus an operation
Mencached specific value may be used as a counter. The plus and minus an atomic operation, but when the initial values are set, the memcached not assigned an initial value.