Memcached is a free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.
Memcached is a brilliant, simple application, which scales very well. I have used it extensively for caching database queries.
Imagine you are sending a repeated database query – consider the diagram below:
- Your application gets ready to execute a query to the Database
- The application checks the Memcached server to see if the ‘hash’ or ‘key’ exists in Memcached’s data store
- If it exists, this is returned from memory to your application (very fast)
- If it does not exist, it receives a null response and then sends the request to the database server (slower)
- Once it receives the response from the Database server, it creates a hash/key and inserts that response into Memcached for the next request.
- When the cycle repeats, that entry is now in Memcached, and is returned to your application (very fast) instead of hitting the Database server (slow!)
This methodology does several things:
- Decreases server (Database) load
- Decreases network traffic (if DB is on a different server)
- Speeds up the response to the applications query (improving UX)