{"id":15821,"date":"2026-06-18T23:11:34","date_gmt":"2026-06-18T22:11:34","guid":{"rendered":"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/"},"modified":"2026-11-16T10:53:14","modified_gmt":"2026-11-16T09:53:14","slug":"what-is-memcached-and-how-does-it-speed-up-your-website","status":"publish","type":"post","link":"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/","title":{"rendered":"What Is Memcached and How Does It Speed Up Your Website?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_87 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#What_Is_Memcached\" >What Is Memcached?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#How_Does_Memcached_Work\" >How Does Memcached Work?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Cache_hits_and_cache_misses\" >Cache hits and cache misses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Keys_values_and_expiry_times\" >Keys, values and expiry times<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Memory_allocation_and_eviction\" >Memory allocation and eviction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#How_distributed_Memcached_servers_work\" >How distributed Memcached servers work<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Why_Can_Memcached_Improve_Website_Performance\" >Why Can Memcached Improve Website Performance?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Key_Benefits_of_Memcached\" >Key Benefits of Memcached<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Lower_database_workload\" >Lower database workload<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Faster_access_to_reusable_data\" >Faster access to reusable data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#More_headroom_during_busy_periods\" >More headroom during busy periods<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Flexible_deployment\" >Flexible deployment<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Who_Should_Consider_Using_Memcached\" >Who Should Consider Using Memcached?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Memcached_vs_Redis_What_Is_the_Difference\" >Memcached vs Redis: What Is the Difference?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#How_to_Install_and_Configure_Memcached_on_a_Linux_Server\" >How to Install and Configure Memcached on a Linux Server<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#1_Install_the_Memcached_service\" >1. Install the Memcached service<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#2_Restrict_the_listening_interface\" >2. Restrict the listening interface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#3_Review_memory_and_service_settings\" >3. Review memory and service settings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#4_Start_the_service_and_check_its_status\" >4. Start the service and check its status<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#How_to_Use_Memcached_with_PHP\" >How to Use Memcached with PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#How_to_Check_Whether_Memcached_Is_Working\" >How to Check Whether Memcached Is Working<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Memcached_Security_Best_Practices\" >Memcached Security Best Practices<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Common_Memcached_Problems_and_Troubleshooting\" >Common Memcached Problems and Troubleshooting<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#The_application_cannot_connect\" >The application cannot connect<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Cache_hit_rate_is_low\" >Cache hit rate is low<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Users_see_stale_information\" >Users see stale information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Items_are_evicted_too_often\" >Items are evicted too often<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Memcached_makes_the_application_slower\" >Memcached makes the application slower<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Is_Memcached_a_database\" >Is Memcached a database?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Does_Memcached_automatically_speed_up_WordPress\" >Does Memcached automatically speed up WordPress?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Can_Memcached_and_Redis_be_used_together\" >Can Memcached and Redis be used together?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#What_port_does_Memcached_use\" >What port does Memcached use?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Does_Memcached_keep_data_after_a_restart\" >Does Memcached keep data after a restart?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/da-manager.com\/blog\/what-is-memcached-and-how-does-it-speed-up-your-website\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p>When a website repeatedly retrieves the same information from a database, those queries can become an unnecessary source of delay and server load. <strong>Memcached<\/strong> helps address this problem by keeping frequently requested data in memory, where an application can retrieve it without repeating the original database operation every time.<\/p>\n<p>This guide explains what Memcached is, how its caching model works, when it can improve performance, how it compares with Redis, and what to consider when installing and securing it. It is especially useful for developers and website owners managing dynamic applications, busy databases or hosting environments with suitable server access.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_Memcached\"><\/span>What Is Memcached?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memcached is a free, open-source, distributed memory object caching system. It stores small pieces of data, such as strings or serialised application objects, as key-value pairs in RAM. Applications commonly use it to cache the results of database queries, API requests or other operations that would otherwise need to be repeated.<\/p>\n<p>Memcached is an ephemeral cache, not a database or permanent storage system. Cached entries can expire or be removed to make room for other data. Your application must be able to retrieve or rebuild the original information from its authoritative source when a cache entry is missing.<\/p>\n<p>Memcached also does not accelerate application code automatically. Developers must integrate a Memcached client into the application and decide what should be cached, how cache keys are formed, how long entries remain valid and when they should be invalidated.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_Does_Memcached_Work\"><\/span>How Does Memcached Work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memcached uses a straightforward key-value model. The application stores a value under a unique key and later requests that value using the same key. The Memcached service keeps the item in memory until it expires or is evicted.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Cache_hits_and_cache_misses\"><\/span>Cache hits and cache misses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li><strong>Check the cache:<\/strong> The application creates a key for the information it needs and asks Memcached for the matching value.<\/li>\n<li><strong>Cache hit:<\/strong> If the item exists and has not expired, Memcached returns it to the application. The application can avoid repeating the underlying database query or API request.<\/li>\n<li><strong>Cache miss:<\/strong> If the item is absent or expired, the application retrieves the information from the database or other source.<\/li>\n<li><strong>Store the result:<\/strong> The application saves the result in Memcached with an appropriate expiry time, then returns it to the user.<\/li>\n<li><strong>Reuse it:<\/strong> Later requests for the same key can use the cached value until it expires or is invalidated.<\/li>\n<\/ol>\n<p>This pattern is often called cache-aside or lazy loading. The application, rather than Memcached, decides when to read from the original data source and when to populate the cache. The official <a href=\"https:\/\/docs.memcached.org\/userguide\/\" target=\"_blank\" rel=\"noopener\">Memcached user guide<\/a> provides examples of this integration pattern.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Keys_values_and_expiry_times\"><\/span>Keys, values and expiry times<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Every cached item has a key and a value, with optional flags and an expiry time. Keys should be predictable, unique for the data they represent and designed to avoid collisions between users, languages, sites or versions of an object. Avoid placing untrusted raw user input directly into keys.<\/p>\n<p>Expiry, also known as time to live (TTL), controls how long an item may remain valid. A short TTL can reduce the time stale information is served, while a longer TTL can improve cache reuse for data that changes infrequently. Choose expiry times according to how often the underlying information changes and how quickly users need to see updates.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Memory_allocation_and_eviction\"><\/span>Memory allocation and eviction<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Memcached stores cache items in allocated memory. When memory is under pressure, it can reclaim expired entries and evict other items to make room for new ones. Its memory management uses slab classes and LRU-based eviction behaviour. This means a cached item is never guaranteed to remain available for its full intended lifetime.<\/p>\n<p>Your application must treat a missing item as a normal cache miss and be able to rebuild it. Monitor evictions as well as hit and miss counts: frequent evictions can indicate that the cache allocation, item sizes or workload need attention.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_distributed_Memcached_servers_work\"><\/span>How distributed Memcached servers work<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A deployment can use more than one Memcached server. The client library receives the server list and uses a client-side hashing strategy to decide which server should hold a particular key. This can increase the total cache capacity and distribute requests across multiple machines.<\/p>\n<p>Memcached servers do not automatically communicate with one another, replicate their contents or synchronise cache entries. The client is responsible for selecting the server for a key and handling server availability. This distinction matters when planning failover, invalidation and changes to the server pool. See the official <a href=\"https:\/\/docs.memcached.org\/\" target=\"_blank\" rel=\"noopener\">Memcached overview and design notes<\/a> for details.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_Can_Memcached_Improve_Website_Performance\"><\/span>Why Can Memcached Improve Website Performance?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Dynamic websites often assemble pages by retrieving records, checking permissions, calculating values or calling external services. If the same expensive result is requested repeatedly, the application may be able to cache it and avoid doing the work again on every request.<\/p>\n<p>When a suitable cache hit replaces a slow database operation, the application may respond more quickly and the database may have more capacity for requests that genuinely need it. The overall benefit depends on the workload, network layout, cache hit rate, item size, application code and the performance of the original data source. Memcached will not necessarily help a site whose database queries are already fast or whose workload rarely reuses the same data.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Key_Benefits_of_Memcached\"><\/span>Key Benefits of Memcached<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Lower_database_workload\"><\/span>Lower database workload<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Frequently requested query results can be served from memory rather than recalculated or fetched repeatedly. This can reduce database query volume and leave more database capacity for writes and uncached reads.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Faster_access_to_reusable_data\"><\/span>Faster access to reusable data<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Retrieving a small cached value from a nearby Memcached service can be quicker than running a complex query or calling a remote API. The improvement is most useful when the saved operation is more expensive than the cache lookup itself.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"More_headroom_during_busy_periods\"><\/span>More headroom during busy periods<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>When many visitors request the same reusable data, caching can reduce repeated work. This may help an application handle higher traffic, although caching is only one part of capacity planning. Application workers, database connections, network limits and server resources still matter.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Flexible_deployment\"><\/span>Flexible deployment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Memcached has client libraries for many programming languages and can run on common Linux and BSD-like systems. It can be used by custom applications and by platforms that provide a supported integration or plugin.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Who_Should_Consider_Using_Memcached\"><\/span>Who Should Consider Using Memcached?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memcached can be useful for applications with repeated, read-heavy access to data that can safely be reused for a defined period. Examples include:<\/p>\n<ul>\n<li><strong>E-commerce websites:<\/strong> Cache selected catalogue data, category information or other frequently requested content, while taking care not to serve stale stock, price or customer-specific information.<\/li>\n<li><strong>Content-heavy websites:<\/strong> Cache reusable page fragments, navigation data or query results that are expensive to generate.<\/li>\n<li><strong>Membership platforms and forums:<\/strong> Cache public profile data, settings or frequently accessed records where the application can manage invalidation correctly.<\/li>\n<li><strong>Custom web applications and APIs:<\/strong> Cache responses from costly database queries or external services when the data&#8217;s freshness requirements allow it.<\/li>\n<\/ul>\n<p>For WordPress, Drupal, Joomla and other content management systems, support depends on the platform version, plugins, extensions and hosting configuration. Confirm that the application has a maintained Memcached integration and that the hosting provider supports the required service and client extension.<\/p>\n<p>If database activity is a major part of your performance problem, it may also help to understand <a href=\"https:\/\/da-manager.com\/blog\/what-is-mysql-and-why-does-web-hosting-use-it\/\">how MySQL is used in web hosting<\/a>. Caching should complement a well-designed database, not conceal inefficient queries or missing indexes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Memcached_vs_Redis_What_Is_the_Difference\"><\/span>Memcached vs Redis: What Is the Difference?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memcached and Redis are both widely used in-memory data services, but they have different feature sets and design priorities. The best choice depends on what the application needs to store and how that data must behave.<\/p>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>Memcached<\/th>\n<th>Redis<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Data model<\/td>\n<td>Simple key-value items; values are supplied by the application, commonly as serialised data<\/td>\n<td>Key-value store with built-in data structures such as strings, hashes, lists, sets and sorted sets<\/td>\n<\/tr>\n<tr>\n<td>Primary use<\/td>\n<td>Simple, high-performance object caching<\/td>\n<td>Caching and additional data-service use cases that need richer operations<\/td>\n<\/tr>\n<tr>\n<td>Persistence<\/td>\n<td>Cache data is normally volatile and should be rebuildable<\/td>\n<td>Optional persistence mechanisms are available<\/td>\n<\/tr>\n<tr>\n<td>Distributed setup<\/td>\n<td>Clients distribute keys across independent Memcached servers<\/td>\n<td>Offers several deployment and replication options, depending on the Redis edition and configuration<\/td>\n<\/tr>\n<tr>\n<td>Complexity<\/td>\n<td>Small feature set and a straightforward cache model<\/td>\n<td>Broader feature set with more choices to understand and operate<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Choose Memcached when a simple, disposable object cache meets the application&#8217;s needs. Consider Redis when the application needs richer data structures, atomic operations or persistence features. Neither product is automatically faster for every workload. Benchmark the actual application and compare operational requirements before choosing. You can also read our separate guide to <a href=\"https:\/\/da-manager.com\/blog\/what-is-redis-and-how-to-use-it-with-web-hosting\/\">Redis and its use in web hosting<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Install_and_Configure_Memcached_on_a_Linux_Server\"><\/span>How to Install and Configure Memcached on a Linux Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Installation requires server-level access. The following example uses Debian or Ubuntu; package names, service management and configuration paths can differ between distributions. On managed or shared hosting, ask the provider whether Memcached is available rather than attempting commands that require administrator privileges.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Install_the_Memcached_service\"><\/span>1. Install the Memcached service<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>On a Debian or Ubuntu server, update the package list and install the service using the operating system package manager:<\/p>\n<pre><code>sudo apt update\nsudo apt install memcached libmemcached-tools<\/code><\/pre>\n<p>Using distribution packages makes it easier to receive operating-system security updates. Check the package version and distribution documentation if you need a feature that is not included in the available release.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Restrict_the_listening_interface\"><\/span>2. Restrict the listening interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For an application running on the same server, configure Memcached to listen only on the loopback interface where possible. A typical configuration uses <code>127.0.0.1<\/code> and the default TCP port <code>11211<\/code>. If application servers connect over a private network, bind to the required private interface and restrict access with a firewall to trusted hosts.<\/p>\n<p>Do not expose Memcached directly to the public internet. It is not designed to be a publicly accessible service. The official <a href=\"https:\/\/docs.memcached.org\/serverguide\/configuring\/\" target=\"_blank\" rel=\"noopener\">server configuration guide<\/a> explains network binding and connection options.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Review_memory_and_service_settings\"><\/span>3. Review memory and service settings<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Review the service configuration file used by your distribution, commonly <code>\/etc\/memcached.conf<\/code> on Debian and Ubuntu. Set a sensible memory limit based on available RAM and the needs of the application. Do not allocate so much memory to the cache that the operating system, database or application processes are forced to swap.<\/p>\n<p>UDP is disabled by default in modern Memcached releases from version 1.5.6. Keep it disabled unless your application has a specific, justified requirement. The official <a href=\"https:\/\/docs.memcached.org\/advisories\/ddos\/\" target=\"_blank\" rel=\"noopener\">Memcached UDP security advisory<\/a> explains the risks and mitigation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Start_the_service_and_check_its_status\"><\/span>4. Start the service and check its status<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>On a system using systemd, you can enable and start the service, then check whether it is running:<\/p>\n<pre><code>sudo systemctl enable --now memcached\nsudo systemctl status memcached<\/code><\/pre>\n<p>Use the service manager and commands appropriate to your Linux distribution. If the service fails to start, inspect its logs and configuration before changing resource or network settings.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Use_Memcached_with_PHP\"><\/span>How to Use Memcached with PHP<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>PHP applications need a compatible client extension or library to communicate with the Memcached service. The PHP <a href=\"https:\/\/www.php.net\/manual\/en\/book.memcached.php\" target=\"_blank\" rel=\"noopener\">Memcached extension documentation<\/a> describes the <code>Memcached<\/code> class and its methods. Installing the server alone does not add caching to a PHP application.<\/p>\n<p>A simplified example of using the PHP Memcached extension is shown below. It assumes the extension is installed and the Memcached service is reachable on the local machine:<\/p>\n<pre><code>&lt;?php\n$cache = new Memcached();\n$cache-&gt;addServer('127.0.0.1', 11211);\n\n$key = 'homepage:featured-items';\n$items = $cache-&gt;get($key);\n\nif ($items === false) {\n    \/\/ Replace this with the application's real data retrieval logic.\n    $items = loadFeaturedItemsFromDatabase();\n\n    \/\/ Cache the result for 300 seconds.\n    $cache-&gt;set($key, $items, 300);\n}\n\n\/\/ Continue rendering the page with $items.\n?&gt;<\/code><\/pre>\n<p>This is an illustrative pattern, not a complete drop-in script. In production, handle connection errors, distinguish a genuine cache miss from other client errors where appropriate, and ensure that the cache key and invalidation rules match the data being stored. Never use cached values as the only copy of important business or customer data.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Check_Whether_Memcached_Is_Working\"><\/span>How to Check Whether Memcached Is Working<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Check both the service and the application&#8217;s cache behaviour. A running daemon does not prove that the application is using it effectively.<\/p>\n<ul>\n<li><strong>Check service status:<\/strong> Confirm that the Memcached service is active and listening only on the intended interface.<\/li>\n<li><strong>Check application integration:<\/strong> Confirm that the application can connect using its configured client and that cache reads and writes are succeeding.<\/li>\n<li><strong>Review statistics:<\/strong> Inspect counters such as <code>get_hits<\/code>, <code>get_misses<\/code>, current items, bytes used and evictions. Calculate the hit rate as hits divided by hits plus misses, where the counters are available.<\/li>\n<li><strong>Measure the real workload:<\/strong> Compare database query volume, response times and resource use before and after enabling caching. Test representative pages and requests rather than relying on a single measurement.<\/li>\n<\/ul>\n<p>The official <a href=\"https:\/\/docs.memcached.org\/serverguide\/maintenance\/\" target=\"_blank\" rel=\"noopener\">maintenance guide<\/a> explains useful statistics and monitoring considerations. A high hit rate can be helpful, but it is not a goal in isolation: the cache must also return correct, sufficiently fresh data.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Memcached_Security_Best_Practices\"><\/span>Memcached Security Best Practices<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Bind the service to localhost or a private network interface, not a public interface.<\/li>\n<li>Use firewall rules to allow connections only from application servers that need access.<\/li>\n<li>Keep UDP disabled unless it is explicitly required and understood.<\/li>\n<li>Keep Memcached and its operating-system packages updated.<\/li>\n<li>Do not store passwords, payment details, authentication secrets or other sensitive data in a cache unless the application has a clear security design for doing so.<\/li>\n<li>Use unpredictable, well-scoped cache keys and avoid raw untrusted input in keys.<\/li>\n<li>Monitor access, errors, memory use and unexpected traffic.<\/li>\n<\/ul>\n<p>For more information, consult the official <a href=\"https:\/\/docs.memcached.org\/serverguide\/configuring\/\" target=\"_blank\" rel=\"noopener\">Memcached configuration guidance<\/a> and <a href=\"https:\/\/docs.memcached.org\/advisories\/ddos\/\" target=\"_blank\" rel=\"noopener\">security advisory<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_Memcached_Problems_and_Troubleshooting\"><\/span>Common Memcached Problems and Troubleshooting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"The_application_cannot_connect\"><\/span>The application cannot connect<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Check that the service is running, the host and port are correct, the PHP or application client is installed, and firewall rules allow the connection. If the service is bound to localhost, a separate application server will not be able to reach it through that address.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Cache_hit_rate_is_low\"><\/span>Cache hit rate is low<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Review whether requests reuse the same keys, whether TTL values are too short, whether keys vary unnecessarily and whether the application is actually reading from the cache before querying the database. A low hit rate may also be normal for workloads with unique or rapidly changing data.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Users_see_stale_information\"><\/span>Users see stale information<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Review expiry times and invalidation logic. When the source record changes, the application may need to delete the related key or write the updated value to the cache. Avoid caching data for longer than the application&#8217;s freshness requirements allow.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Items_are_evicted_too_often\"><\/span>Items are evicted too often<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Check memory allocation, item sizes, slab statistics and the number of distinct keys. Increasing the memory limit may help if the server has spare RAM, but first make sure the cache is not competing with the database or application for essential memory.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Memcached_makes_the_application_slower\"><\/span>Memcached makes the application slower<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A cache lookup adds work and may involve a network round trip. If the original query is already fast, the cache hit rate is low or the application makes many individual cache requests, Memcached may not improve performance. Profile the complete request path and compare results with and without the cache.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Is_Memcached_a_database\"><\/span>Is Memcached a database?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. Memcached is an in-memory cache for temporary data. Applications should keep authoritative records in a database or another durable storage system and be able to rebuild cache entries when they disappear.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_Memcached_automatically_speed_up_WordPress\"><\/span>Does Memcached automatically speed up WordPress?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. WordPress or another application needs a compatible object-cache integration, and the hosting environment must provide the service and any required PHP extension. Performance gains depend on the site&#8217;s workload and cache configuration.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_Memcached_and_Redis_be_used_together\"><\/span>Can Memcached and Redis be used together?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Some systems can use both, but doing so adds operational complexity. Use each only where there is a clear application requirement, and avoid duplicating caches without a defined reason.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_port_does_Memcached_use\"><\/span>What port does Memcached use?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The common default TCP port is <code>11211<\/code>. Administrators can change the port and listening interface. The service should remain accessible only to trusted application hosts.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_Memcached_keep_data_after_a_restart\"><\/span>Does Memcached keep data after a restart?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In normal use, cached items are volatile and should be treated as disposable. Applications must be able to repopulate the cache from the original data source.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Memcached is a simple, effective option for caching frequently reused application data in memory. When a website repeatedly performs expensive database queries or retrieves the same information, a well-designed cache can reduce repeated work and improve response times.<\/p>\n<p>The best results come from careful application integration, sensible expiry and invalidation rules, monitoring and secure server configuration. First identify a measurable performance bottleneck, then test whether Memcached addresses it. It is a useful part of a performance strategy, not a substitute for efficient code, database optimisation or suitable hosting resources.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn what Memcached is, how in-memory caching works, how it reduces database load, and how to configure it securely for better website performance.<\/p>\n","protected":false},"author":16,"featured_media":16470,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[147,219],"tags":[3948,3949,4019,3989,3950,232,314,3944],"class_list":["post-15821","post","type-post","status-publish","format-standard","has-post-thumbnail","category-general","category-hosting","tag-database-hosting","tag-mysql-explained","tag-performance","tag-php","tag-php-mysql","tag-server","tag-vps-hosting","tag-website-performance"],"jetpack_featured_media_url":"https:\/\/da-manager.com\/blog\/wp-content\/uploads\/2026\/11\/memcached-caching-guide.jpg","_links":{"self":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/comments?post=15821"}],"version-history":[{"count":1,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15821\/revisions"}],"predecessor-version":[{"id":16471,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15821\/revisions\/16471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media\/16470"}],"wp:attachment":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media?parent=15821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/categories?post=15821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/tags?post=15821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}