Nodea — logo

Memcached

Memcached is an open-source, distributed in-memory caching system that stores data in the server's RAM as simple key-value pairs. Its job is to speed up dynamic applications and websites by temporarily holding the results of expensive operations — most often database queries — so they don't have to be executed every time.

How Memcached works

Memcached runs as a background service that the application sends key-value pairs to. When a script needs data, it first checks the cache: if the value exists (a hit), it is retrieved instantly from RAM; if not (a miss), the script computes the result, stores it in Memcached and returns it. Each entry can be given a time to live (TTL) after which it expires. Data lives in memory only — after a service restart the cache is empty, which is acceptable because it is a buffer layer, not permanent storage. Memcached is multithreaded and scales out easily across many servers.

Practical application

Memcached most often caches SQL query results, rendered page fragments, user session data or API objects. In the PHP ecosystem, popular applications use it — WordPress, Magento and Drupal all offer plugins and modules that integrate Memcached as an object cache backend, significantly reducing database load under high traffic.

On VPS and dedicated servers, Memcached is often part of a performance stack alongside OPcache (which caches compiled PHP code) and page caching. In newer deployments it is increasingly replaced by Redis, which offers richer data structures and optional persistence, but for simple, fast value caching Memcached remains a lightweight and battle-tested solution.

Powiązane pojęcia

Najczęstsze pytania

What is the difference between Memcached and Redis?

Memcached is a simple, multithreaded key-value cache that keeps data in RAM only, with no disk persistence. Redis offers richer data structures (lists, sets, hashes), data persistence, replication and pub/sub messaging. Memcached can be lighter for plain caching of simple values, while Redis is more versatile and more often chosen for new projects.