Skip to content

What is Memcached? Object Caching System

Last updated: 31 December 2025

What is Memcached?

Memcached is a high-performance distributed memory caching system that stores data in RAM for fast access. It's designed to reduce database load by storing frequently requested data in memory, allowing websites and applications to respond significantly faster. For web hosting, Memcached is mainly used as object cache for WordPress and other content management systems.

The system works as a simple but extremely fast key-value datastore. You store data under a unique key and retrieve it lightning-fast later. By storing everything in RAM instead of on disk, Memcached can process millions of requests per second. This makes it ideal for high-traffic websites that need to perform fast under heavy load.

How Memcached Works

Memcached runs as a daemon (background process) on your server and listens on a specific port (default 11211). When your WordPress site needs data, it first checks if it's available in Memcached. If yes, the data is retrieved directly from memory. If no, WordPress fetches the data from MySQL, shows it to the visitor, and simultaneously stores it in Memcached for next times.

The system uses a simple hash table structure where each value is identified by a unique key. For a WordPress menu, the key could for example be "main_menu_v2". When your menu changes, the old cached version is invalidated and replaced by a new one with an updated key.

Memcached is distributed by design, meaning you can use multiple Memcached servers working together as one large cache system. For high-traffic websites you can distribute the cache load across different servers. This scales horizontally: more traffic simply means adding more Memcached nodes.

Memory management is intelligent. When Memcached fills up, it uses an LRU (Least Recently Used) algorithm to remove old, unused data and make room for new data. This happens automatically without intervention, ensuring your cache always contains the most relevant data.

Benefits of Memcached

The main benefits are speed and scalability. Memcached retrieves data in microseconds, where database queries can take milliseconds to seconds. For a WordPress site this means pages that load 3-5 times faster. Especially with high traffic, this difference is enormously noticeable.

Server resources are drastically saved. Without object caching, your MySQL database must execute the same queries at every pageview. With Memcached these queries are done once and the result is reused. This reduces CPU and disk I/O usage by 50-80%.

TTFB (Time To First Byte) improves significantly. Database queries are often the biggest bottleneck in server response time. By caching frequently used queries, your server responds 200-500ms faster. This improvement is directly measurable and valuable for SEO rankings.

Simplicity is another advantage. Memcached has a minimalist design without complex features. It does one thing (caching) and does it excellently. For teams wanting to implement quickly without long configuration, this is attractive.

Installing and Configuring Memcached

With many hosting providers, Memcached is pre-installed or available as an add-on. Check your cPanel, Plesk, or DirectAdmin dashboard for Memcached options. With managed WordPress hosting it's often activated by default.

For VPS or dedicated servers, install Memcached via SSH. On Ubuntu/Debian: sudo apt install memcached libmemcached-tools. On CentOS/RHEL: sudo yum install memcached. Start the service with sudo systemctl start memcached and enable for auto-start: sudo systemctl enable memcached.

For WordPress, install an object cache plugin. The most popular options are W3 Total Cache and WP Super Cache, both supporting Memcached. Configure in the plugin settings Memcached as object cache method and provide the server details (usually localhost:11211).

Test if Memcached works with echo stats | nc localhost 11211. This shows statistics like memory usage, cache hits and misses. A good hit ratio is 85-95%, meaning most data comes from cache instead of database queries.

Memcached vs Redis

Both are in-memory caching solutions with comparable performance for simple key-value operations. The big difference is in features and flexibility. Redis supports complex data structures (lists, sets, hashes) where Memcached only knows key-value pairs. For WordPress object caching this makes little practical difference.

Redis offers data persistence with periodic snapshots to disk. Memcached stores everything only in memory and loses data at restart. For caching purposes this isn't a problem, but if you want to store sessions or other semi-permanent data, Redis wins.

In memory efficiency, Memcached is slightly better for simple caching workloads. It has less overhead and uses memory more efficiently for pure key-value storage. Redis has more features but therefore also uses slightly more resources.

Community and ecosystem: Redis has more momentum in 2025 with more active development and broader hosting support. For new projects, Redis is more often recommended. But Memcached is still robust, stable, and perfectly suited for straightforward caching needs.

Using Memcached Optimally

Allocate sufficient memory but not too much. A typical WordPress site runs well on 128-256MB Memcached memory. Too little means constant cache evictions, too much wastes resources that PHP and MySQL can use. Monitor usage and adjust based on hit ratio.

Set the right item size limit. By default, Memcached accepts items up to 1MB. For WordPress object caching this is sufficient. If you try to cache entire pages or large images, you need to increase the limit via -I parameter when starting Memcached.

Use connection pooling to efficiently manage database connections. Instead of opening a new Memcached connection at every PHP request, you reuse persistent connections. This reduces overhead and improves performance. Modern WordPress caching plugins do this automatically.

Monitor performance metrics regularly. Check hit rate, eviction rate, and memory usage. A declining hit rate indicates problems: maybe your TTL is too short, your memory too small, or your cache is flushed too often. Tools like memcached-tool or phpMemcachedAdmin help with monitoring.

Memcached Troubleshooting

With low hit ratios, first check your TTL (Time To Live) settings. Too short TTLs mean data expires before it can be reused. For WordPress menus and widget content, a TTL of 12-24 hours is realistic. For changing content like homepage posts, 5-15 minutes is better.

If Memcached crashes or is unreachable, WordPress falls back on direct database queries. Your site keeps working but becomes slower. Check if the Memcached service is running: sudo systemctl status memcached. Restart if needed: sudo systemctl restart memcached.

Memory exhaustion happens when Memcached fills up and must aggressively evict old items. You see this in a high eviction rate. Solutions: increase allocated memory, optimize what you cache, or add a second Memcached instance to distribute load.

Connection errors often indicate firewall issues. Check if your firewall allows connections on port 11211. For local connections (localhost) this is rarely a problem, but with distributed setups you need to add explicit firewall rules.

Memcached Security

By default, Memcached has no authentication, which is a security risk if externally accessible. Therefore always bind Memcached to localhost (127.0.0.1) unless you specifically need distributed caching. This prevents outsiders from reading or manipulating your cache.

For setups requiring external access, use SASL authentication. Configure this in memcached.conf with username and password. Modern Memcached versions support SASL, but it requires extra configuration.

Update Memcached regularly to the latest version. Older versions have known vulnerabilities like buffer overflows. With managed hosting this happens automatically. With your own VPS check: memcached -h shows the version. Compare with the latest release on memcached.org.

Monitor access logs for unusual patterns. Many failed connections, unknown IPs, or strange commands can indicate attacks. With VPS configure logging in memcached.conf and review logs periodically.

Memcached for WordPress Performance

WordPress is an ideal use case for Memcached. Without object cache, WordPress executes dozens of database queries at every pageview for menus, widgets, user data, and post content. With Memcached these results are cached, reducing server load by 60-80%.

Combine Memcached with page caching for maximum speed. Memcached caches database queries (object cache), page caching caches complete HTML pages. Together they ensure optimal performance. Plugins like W3 Total Cache support both simultaneously.

Test your performance before and after Memcached implementation with tools like GTmetrix or Pingdom. Measure TTFB, database query time, and total load time. Expect 30-50% speed improvement for average WordPress sites, more for sites with complex queries.

For WooCommerce webshops, Memcached is valuable for product catalogs and shopping cart data. Product information that rarely changes can be cached long-term. Cart data you cache with short TTL to guarantee timeliness while still getting performance benefits.

Memcached Hosting Requirements

Not all hosting packages offer Memcached. Budget shared hosting rarely has it. When choosing hosting providers, check if Memcached is available. VPS and dedicated servers give full control to install it yourself.

You need at least 256MB extra RAM for Memcached, on top of what your OS, web server, PHP, and MySQL use. For a comfortable WordPress setup with Memcached, count on at least 2GB total RAM, ideally 4GB or more.

With cPanel hosting, check under "PHP Extensions" if Memcached is available. With Plesk, go to "PHP Settings" and check the installed extensions. Not all providers enable Memcached by default, sometimes you need to ask support to activate it.

Managed WordPress hosting providers like Kinsta or WP Engine often use their own optimized caching solutions or prefer Redis. Check which object cache technology your provider uses and whether you have influence on the configuration.

Memcached Alternatives and Migration

If you're considering migrating from Memcached to Redis, the switch is relatively simple. For WordPress you simply change your object cache plugin configuration from Memcached to Redis. Data is lost during the switch (it's cache, not permanent storage), but functionality remains identical.

For pure caching without advanced features, Memcached remains a solid choice. It's battle-tested, stable, and does exactly what it needs to do without complexity. For sites not needing Redis-specific features, there's no compelling reason to switch.

APCu is an alternative for single-server setups. It caches PHP opcode and can also serve as object cache. For small sites on shared hosting, APCu is lighter than Memcached. But it doesn't scale across multiple servers and has fewer features.

File-based caching is the fallback when no in-memory cache is available. It's slower than Memcached but better than no cache. Modern WordPress plugins automatically detect which caching methods are available and choose the fastest option. Check our hosting comparison for providers with optimal caching support.

Frequently Asked Questions

How much does web hosting cost on average?

Web hosting costs between €3 and €15 per month for shared hosting on average. VPS hosting starts around €10-€20 per month, and dedicated servers from €50 per month.

Can I upgrade to a different package later?

Yes, with most hosting providers you can easily upgrade to a larger package when your website grows. This can usually be done without downtime.

Is Dutch hosting better than foreign hosting?

For Dutch visitors, Dutch hosting is often faster due to the shorter distance. Additionally, communication with support is easier and you comply with GDPR legislation.

Was this article helpful?

Compare hosting packages directly to find the best choice for your situation.