{"id":5440461,"date":"2023-04-11T12:29:55","date_gmt":"2023-04-11T10:29:55","guid":{"rendered":"https:\/\/wp-rocket.me\/?post_type=caching_hub&#038;p=5440461"},"modified":"2023-05-10T15:41:20","modified_gmt":"2023-05-10T13:41:20","slug":"memcached-what-is-it-how-to-use-it","status":"publish","type":"caching_hub","link":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/","title":{"rendered":"Memcached: What Is It and How to Use It on Your WordPress Site?"},"content":{"rendered":"<p>How many types of caching do you know and use on your WordPress site?<\/p><p>If you\u2019re using a WordPress cache plugin like WP Rocket, there\u2019s no doubt you\u2019re already profiting from its <strong>browser and<\/strong> <strong>page caching <\/strong>features. And if you\u2019re also using its advanced caching options, then your site is enjoying <strong>mobile and user caching <\/strong>too.<\/p><p>Then there\u2019s <strong>server-side caching<\/strong> (like Varnish or NGINX), and <strong>CDN caching<\/strong>: the first depends on the hosting you\u2019re using, while the second on the CDN service you chose.<\/p><p>The last type of caching you\u2019ll want to add to the group is <strong>object caching<\/strong>: this is important to make your database queries run faster and finally improve your website speed.<br><\/p><p>In this post, we\u2019re going to explore the secrets of object caching and dive into one of the most popular object caching systems: <strong>Memcached<\/strong>. <br><br>Memcached shouldn\u2019t be confused with <em>memcache, <\/em>which is a PHP extension created for Memcached caching service, and it\u2019s out of the scope of this post.<\/p><h2 class=\"wp-block-heading\">Memcached And Object Caching Explained In Plain English<\/h2><p>Before getting into the details of Memcached, let\u2019s explain what object caching does precisely.<\/p><p>If page caching takes care of caching static resources (images, HTML, CSS and JS files) and browser caching manages the same resources within the browser, <strong>object caching is devoted to your database<\/strong>.<br><\/p><p>The aim of object caching is to cache query results from your database. You can find a <a href=\"https:\/\/wp-rocket.me\/blog\/object-caching-use-wordpress\/\">detailed explanation of what object caching is on our blog<\/a>.<br><\/p><p>An efficient database is one of the crucial factors for a fast website: WordPress is a content management system which is naturally dependent on its MySQL database.<br><\/p><p>Every time users (or crawlers) make a request on your website, they generate database queries. If your site experiences a large number of requests to the database, queries can quickly pile up, overwhelming your server and slowing down your website.<br><\/p><p>The good news is the WordPress introduced its object caching class a long time<em> <\/em>ago: it was 2005 when the class named <em>WP_Object_Cache<\/em> was implemented into WordPress core.<\/p><h3 class=\"wp-block-heading\">What Does WordPress Object Caching Do?<\/h3><p>WordPress built-in object caching saves a copy of complex queries and stores their results in a database table (i.e., like a HTTPS redirect).<br><\/p><p>The most frequently used queries running on the pages of your site are stored on the database: this copy of the requests allows to reduce load time and make your website more performant.<br><\/p><p>Of course, this process is not a prerogative of WordPress sites: the same thing happens on all sites where an object caching system has been implemented. <br><\/p><p>For example, Drupal, which is another very popular content management system, implements a similar built-in object caching system.<br><\/p><p>If object caching is working, your server won\u2019t have to regenerate queries\u2019 results every time, but it can use the object caching layer previously created.<br><\/p><p>To store an object cache, you can use different technologies: among the most popular object caching engines are Memcached, Redis, and APC.<\/p><h2 class=\"wp-block-heading\">What is Memcached?<\/h2><p>Memcached is an open source distributed memory caching system built to ease database load for dynamic web applications like e-commerce stores or websites where login\/registration is needed.<br><\/p><p>Memcached was initially developed by Brad Fitzpatrick in 2003 and is now used by Facebook, Twitter, YouTube, Wikipedia, and other big and small web applications.<br><\/p><p>Its developers define it as follows:<\/p><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em>Memcached is an in-memory key-value store for small arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.<\/em><\/p><cite>(<a href=\"https:\/\/github.com\/memcached\/memcached\/wiki\/Overview#memcached\">source<\/a>)<\/cite><\/blockquote><p>This system stores key-values data for string and objects, such as:<\/p><ul class=\"wp-block-list\"><li>API calls<\/li>\n\n<li>Page rendering<\/li>\n\n<li>Results of database calls<\/li><\/ul><p>Memcached uses a client-server architecture based on four components:<br><\/p><ul class=\"wp-block-list\"><li>A <strong>client-server<\/strong>, which retains the list of available Memcached servers<\/li>\n\n<li>A <strong>client-based hashing algorithm<\/strong>, which picks up a server based on the requested \u201ckey.\u201c<\/li>\n\n<li>A <strong>server software<\/strong>, which stores the combinations of values + key into an internal hash table<\/li>\n\n<li>A <strong>Least Recently Used (LRU) algorithm,<\/strong> which decides when to use old data or the memory<\/li><\/ul><h3 class=\"wp-block-heading\">How Memcached Works<\/h3><p>Memcached works like other caching systems, but now the database is at the core of the process.<\/p><p>Let\u2019s see the workflow in five quick steps:<br><\/p><ol class=\"wp-block-list\"><li>The client-server receives a query from a user (i.e., access to a specific URL of a website with an HTTPS redirect);<br><br><\/li>\n\n<li>The client-server checks with the Memcached server if the data needed is already stored in its memory;<br><br><\/li>\n\n<li>If the data exists, Memcached directly returns it to the client server;<br><br><\/li>\n\n<li>If the data isn\u2019t already saved in the cache, Memcached forwards the request to the database;<br><br><\/li>\n\n<li>Requested data is now forwarded to the client-server and, at the same time, the Memcache index is updated with these latest values: the cache is now ready to be used in the future (see step 3).<\/li><\/ol><p>Typically, Memcached is set up via different Memcached servers and clients, which help to distribute the load of the requests.<br><\/p><p>The client-server uses the hashing algorithm to decide which Memcached server the request should be forwarded.<br><\/p><p>It\u2019s important to note that Memcached servers don\u2019t share data: so the database sends data only to one Memcached server at a time. <\/p><div id=\"om-olkrjzfbhlynbs54rv6z-holder\"><\/div>\n\t<script>(function (d, u, ac) {\n\t\t\tvar s = d.createElement('script')\n\t\t\ts.type = 'text\/javascript'\n\t\t\ts.src = 'https:\/\/a.omappapi.com\/app\/js\/api.min.js'\n\t\t\ts.async = true\n\t\t\ts.dataset.user = u\n\t\t\ts.dataset.campaign = ac\n\t\t\td.getElementsByTagName('head')[0].appendChild(s)\n\t\t})(document, 20440, 'olkrjzfbhlynbs54rv6z')<\/script><h2 class=\"wp-block-heading\">How To Use Memcached On Your WordPress Site?<\/h2><p>The first condition to use Memcached on your WordPress site is that <strong>your hosting server has it installed<\/strong>. <br>The second condition is that <strong>your web application can support Memcached.<\/strong><\/p><p>Since Memcached is solely relying on RAM, it doesn\u2019t require too many CPU resources. <br><\/p><p>Several web hosting services come with pre-installed Memcached system on their cloud servers: you can find some examples on <a href=\"https:\/\/www.a2hosting.com\/kb\/does-a2-hosting-support\/do-you-support-memcached-hosting\">A2 Hosting<\/a>, <a href=\"https:\/\/www.cloudways.com\/blog\/wordpress-memcached-server-tutorial\/\">Cloudways<\/a> or <a href=\"https:\/\/www.siteground.com\/tutorials\/supercacher\/memcached\/\">Siteground<\/a>. <br><\/p><p>If your server supports Memcached, it\u2019s very likely that you can use it through the pre-built <strong>Memcached PHP extension<\/strong>.<\/p><h3 class=\"wp-block-heading\">What Are The Benefits Of Using Memcached On Your WordPress site?<\/h3><p>The main advantage of Memcached is that <strong>all information is stored in RAM<\/strong>: this means it doesn\u2019t need to be loaded from the disk each time.<\/p><p>Another advantage is that there are <strong>no data restrictions<\/strong>: you can use Memcached to cache a number of different data, such as documents, images but, above all, much more complex structures.<\/p><p>Furthermore, depending on the usage environment you set up, <strong>the failure of one of the Memcached servers isn\u2019t usually critical<\/strong>. Most of the time, in fact, Memcached is used as a read-only cache or to hold temporary information. If you use it for persistent data, you can recede to an alternative lookup method which reloads the data into RAM of a different server.<\/p><h3 class=\"wp-block-heading\">Is WP Rocket Compatible With Memcached?<\/h3><p>Being a plugin focused on page caching, WP Rocket doesn\u2019t take care of object caching. So you won\u2019t find any specific Memcached option.<\/p><p>This doesn\u2019t mean you can\u2019t use Memcached with WP Rocket!<br>To use WP Rocket and Memcached together, <a href=\"https:\/\/docs.wp-rocket.me\/article\/116-does-wp-rocket-support-memcached\">you\u2019ll need to install an additional plugin<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>How many types of caching do you know and use on your WordPress site? If you\u2019re using a WordPress cache plugin like WP&nbsp;Rocket, there\u2019s no doubt you\u2019re already profiting from its browser and page caching features. And if you\u2019re also using its advanced caching options, then your site is enjoying mobile and user caching [&hellip;]<\/p>\n","protected":false},"template":"","class_list":["post-5440461","caching_hub","type-caching_hub","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Memcached: What Is It and How to Use It on Your WordPress Site?<\/title>\n<meta name=\"description\" content=\"In this post we&#039;ll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Memcached: What Is It and How to Use It on Your WordPress Site?\" \/>\n<meta property=\"og:description\" content=\"In this post we&#039;ll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Rocket\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-10T13:41:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2024\/10\/1200x800-Featured-Image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"1365\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wp_rocket\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/\",\"url\":\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/\",\"name\":\"Memcached: What Is It and How to Use It on Your WordPress Site?\",\"isPartOf\":{\"@id\":\"https:\/\/wp-rocket.me\/#website\"},\"datePublished\":\"2023-04-11T10:29:55+00:00\",\"dateModified\":\"2023-05-10T13:41:20+00:00\",\"description\":\"In this post we'll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.\",\"breadcrumb\":{\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wp-rocket.me\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress Cache\",\"item\":\"https:\/\/wp-rocket.me\/wordpress-cache\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Memcached: What Is It and How to Use It on Your WordPress Site?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wp-rocket.me\/#website\",\"url\":\"https:\/\/wp-rocket.me\/\",\"name\":\"WP Rocket\",\"description\":\"Plugin d&#039;optimisation de sites WordPress\",\"publisher\":{\"@id\":\"https:\/\/wp-rocket.me\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wp-rocket.me\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/wp-rocket.me\/#organization\",\"name\":\"WP Rocket\",\"url\":\"https:\/\/wp-rocket.me\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png\",\"contentUrl\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png\",\"width\":150,\"height\":41,\"caption\":\"WP Rocket\"},\"image\":{\"@id\":\"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829\",\"https:\/\/x.com\/wp_rocket\",\"https:\/\/www.youtube.com\/channel\/UC1ozThXHd1IWIZ5wkshgp_Q\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Memcached: What Is It and How to Use It on Your WordPress Site?","description":"In this post we'll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/","og_locale":"en_US","og_type":"article","og_title":"Memcached: What Is It and How to Use It on Your WordPress Site?","og_description":"In this post we'll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.","og_url":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/","og_site_name":"WP Rocket","article_publisher":"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829","article_modified_time":"2023-05-10T13:41:20+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/wp-rocket.me\/wp-content\/uploads\/2024\/10\/1200x800-Featured-Image.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@wp_rocket","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/","url":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/","name":"Memcached: What Is It and How to Use It on Your WordPress Site?","isPartOf":{"@id":"https:\/\/wp-rocket.me\/#website"},"datePublished":"2023-04-11T10:29:55+00:00","dateModified":"2023-05-10T13:41:20+00:00","description":"In this post we'll explore Memcached object caching, and how to use it to boost the web performance of your WordPress site.","breadcrumb":{"@id":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wp-rocket.me\/wordpress-cache\/memcached-what-is-it-how-to-use-it\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wp-rocket.me"},{"@type":"ListItem","position":2,"name":"WordPress Cache","item":"https:\/\/wp-rocket.me\/wordpress-cache\/"},{"@type":"ListItem","position":3,"name":"Memcached: What Is It and How to Use It on Your WordPress Site?"}]},{"@type":"WebSite","@id":"https:\/\/wp-rocket.me\/#website","url":"https:\/\/wp-rocket.me\/","name":"WP Rocket","description":"Plugin d&#039;optimisation de sites WordPress","publisher":{"@id":"https:\/\/wp-rocket.me\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wp-rocket.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/wp-rocket.me\/#organization","name":"WP Rocket","url":"https:\/\/wp-rocket.me\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/","url":"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png","contentUrl":"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png","width":150,"height":41,"caption":"WP Rocket"},"image":{"@id":"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829","https:\/\/x.com\/wp_rocket","https:\/\/www.youtube.com\/channel\/UC1ozThXHd1IWIZ5wkshgp_Q"]}]}},"_links":{"self":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/caching_hub\/5440461"}],"collection":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/caching_hub"}],"about":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/types\/caching_hub"}],"wp:attachment":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/media?parent=5440461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}