Memcached is an open source distributed caching system. It is used to speed up dynamic web applications by reducing database load. In other words, it adds additional load to the server each time a database request is made. Memcached reduces load by storing data objects in dynamic memory (think of it as short-term memory for applications). Memcached stores data based on key/ value pairs for small strings or objects:
- Results of database calls
- API calls
- Create a page
Memcached consists of four main components. These components allow the client and server to work together to deliver cached data as efficiently as possible:
- Client software : Given a list of available Memcached servers
- Client-based hash algorithm : Selects a server based on "key"
- Server software : Saves values and keys to an internal hash table
- LRU : Determines when old data is discarded or when memory is reused
How does Memcached work?
As mentioned above, Memcached consists of four main components, which are elements that allow data storage and receiving. Each elementconsists of key and expiration time and raw data. Memcached at the top level works as follows:
- The client requests a piece of data that Memcached checks to see if it is stored in the cache.
- Here are two possible outcomes:
- If the data is stored in the cache: it returns the data from Memcached (you don't need to check the database).
- If the data is not stored in the cache: queries the database, retrieves the data, and then stores it in Memcached.
- When information is changed or an item expires, Memcached updates its cache to ensure that new content is forwarded to the client.
- Data is sent only to one server.
- Sunucular veri paylaşmaz.
- Servers keep values in RAM. If ram runs out, the oldest value is discarded.