{"id":2159,"date":"2022-08-13T16:17:01","date_gmt":"2022-08-13T19:17:01","guid":{"rendered":"https:\/\/felipeelia.com\/br\/?p=2159"},"modified":"2024-08-05T19:43:42","modified_gmt":"2024-08-05T22:43:42","slug":"wordpress-object-cache-and-redis","status":"publish","type":"post","link":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/","title":{"rendered":"WordPress, Object Cache, and Redis"},"content":{"rendered":"\n<p>Do you want to <strong>make your WordPress website faster while leveling up your WP programming skills<\/strong>? Object Cache may be your answer!<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-3d197fc2      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#before-we-go-into-object-cache-what-is-cache\" class=\"uagb-toc-link__trigger\">Before we go into Object Cache&#8230; What is cache?<\/a><li class=\"uagb-toc__list\"><a href=\"#wordpress-object-cache\" class=\"uagb-toc-link__trigger\">WordPress Object Cache<\/a><li class=\"uagb-toc__list\"><a href=\"#how-to-store-things-in-memory-redis-or-memcached\" class=\"uagb-toc-link__trigger\">How to &quot;store&quot; things in memory? Redis or Memcached<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#what-do-i-need-to-use-wordpress-object-cache-with-redis\" class=\"uagb-toc-link__trigger\">What do I need to use WordPress Object Cache with Redis?<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#the-redis-object-cache-wordpress-plugin\" class=\"uagb-toc-link__trigger\">The Redis Object Cache WordPress plugin<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#same-redis-for-different-sites-at-the-same-server\" class=\"uagb-toc-link__trigger\">Same Redis for different sites at the same server<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#how-the-object-cache-plugin-works\" class=\"uagb-toc-link__trigger\">How the Object Cache plugin works<\/a><li class=\"uagb-toc__list\"><a href=\"#lets-give-a-look-at-some-code\" class=\"uagb-toc-link__trigger\">Let&#039;s give a look at some code<\/a><li class=\"uagb-toc__list\"><a href=\"#cache-functions-available-in-wordpress\" class=\"uagb-toc-link__trigger\">Cache functions available in  WordPress<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#key-value-group-and-expiration\" class=\"uagb-toc-link__trigger\">Key, value, group, and expiration<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#expiration\" class=\"uagb-toc-link__trigger\">Expiration<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#event-driven\" class=\"uagb-toc-link__trigger\">Event-driven<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#time-driven\" class=\"uagb-toc-link__trigger\">Time-driven<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#transients-api-and-object-cache\" class=\"uagb-toc-link__trigger\">Transients API and Object Cache<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#lets-talk\" class=\"uagb-toc-link__trigger\">Let&#039;s talk!<\/a><\/ul><\/ul><\/ul><\/ul><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p>In the <a href=\"https:\/\/felipeelia.com\/what-is-an-api\/\">What is an API<\/a> post, I&#8217;ve briefly mentioned WordPress Object Cache and how I am using Redis here in the blog. In this post, we will give a better look into both of those things.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"antes-de-object-cache-o-que-e-cache\">Before we go into <em>Object Cache<\/em>&#8230; What is cache?<\/h2>\n\n\n\n<p>Before we start talking about Redis, we need to talk about Object Cache. And before we talk about Object Cache &#8212; you saw it coming &#8212; we need to talk about cache in general.<\/p>\n\n\n\n<p>Looking for definitions of what is cache on the Internet, common sense seems to be something like this:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Cache is an <strong>intermediate storage with quick access<\/strong>, placed between the consumer and the main storage, potentially saving a longer trip.<\/p>\n<\/blockquote>\n\n\n\n<p>Look at the example below. In the first request, we go all the way through the origin server but the server cache saves a copy of the response. In the second request, the copy is served, <strong>saving time by not going to the origin server<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x-1024x512.webp\" alt=\"Two line diagram: in the first one the request goes from the client to the cache server and reaches the origin server. In the second one, the cache server answers the request.\" class=\"wp-image-2110\" style=\"width:768px;height:384px\" srcset=\"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x-1024x512.webp 1024w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x-300x150.webp 300w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x-768x384.webp 768w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/cache-definition-lg2x.webp 1460w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Image credits: <a href=\"https:\/\/www.keycdn.com\/support\/cache-definition-explanation\">KeyCDN blog<\/a>.<\/figcaption><\/figure>\n\n\n\n<p>With that in mind, we can start thinking about all the several trips needed to visit a website and all the intermediate steps we can insert to save time:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Browser cache<\/strong><\/td><td>Between your browser and the site server, if there is a <strong>valid copy of the page on your computer<\/strong>, we save a trip. In fact, we save the entire trip in this case.<\/td><\/tr><tr><td><strong>CDN<\/strong><\/td><td>If you are using a CDN like Cloudflare on your website and <strong>if there is a valid copy of the content in the CDN<\/strong>, there is no reason to ask for a new copy. It is enough to send just the copy and we save a trip.<\/td><\/tr><tr><td><strong>WP&#8217;s cache<\/strong><\/td><td>In your WordPress website, if a post was already brought from the database and <strong>if the version of the post in memory is still valid<\/strong>, why go to the database again?<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>There are lots of other intermediate places we could save a version of the information, these are just some examples.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"o-object-cache-do-wordpress\">WordPress Object Cache<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>WordPress Object Cache<\/em> is simple and understand how it works can make the difference during your next job interview \ud83d\ude09<\/p>\n<\/blockquote>\n\n\n\n<p>As I said in the <a href=\"https:\/\/felipeelia.com\/what-is-an-api\/\">What is an API<\/a> post, memory access is always faster than disk access. With that in mind, <strong>if we brought a post from the database and put that in memory, we do not need to go to the database to fetch it again<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/memory-hierarchy.png\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"479\" src=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/memory-hierarchy.png\" alt=\"Extended Memory Hierarchy. From bottom to top: Off-line Storage (slower), Hard Disk, RAM, Cache, CPU Registers (faster.) The faster, the more expensive it is.\" class=\"wp-image-2119\" srcset=\"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/memory-hierarchy.png 638w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/memory-hierarchy-300x225.png 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/a><figcaption class=\"wp-element-caption\">The image quality is not very good but the image is great to understand the relationship between storage and speed.<\/figcaption><\/figure>\n\n\n\n<p>The problem is that in WordPress default implementation, <strong>it will be in memory only until the end of the request<\/strong>. If the user refreshes the page, we will need to go to the database again.<\/p>\n\n\n\n<p>MySQL is smart enough to notice if a piece of information was requested recently and will make it available in a quicker way (basically storing it in its own memory part). <strong>Although faster, it will not be as faster as not going to MySQL at all.<\/strong> <\/p>\n\n\n\n<p>By default, this post (or any other piece of info we want) requested at the beginning of the execution is <strong>stored using a class called <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_object_cache\">WP_Object_Cache<\/a><\/strong>. Its main goal is to save trips to the database and it works basically using key-value pairs. The problem is, like I said, all that only lasts one request. For the next one, we have to do everything again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"como-gravar-coisas-na-memoria-redis-ou-memcached\">How to &#8220;store&#8221; things in memory? Redis or Memcached<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p><strong>Softwares like <a href=\"https:\/\/redis.io\/\">Redis<\/a> or <a href=\"https:\/\/memcached.org\/\">Memcached<\/a> are in-memory databases.<\/strong> They can do more than that &#8212; especially Redis &#8212; but for our problem with WordPress, its key-pair value in-memory storage is everything we need.<\/p>\n\n\n\n<p>In this post, I will use Redis as an example but Memcached installation and usage are very similar.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-group redes-sociais-inline has-background is-layout-flow wp-block-group-is-layout-flow\" style=\"background-color:#f0f0f0\">\n<div class=\"wp-block-uagb-info-box uagb-block-335d44f6 uagb-infobox__content-wrap  uagb-infobox-icon-above-title uagb-infobox-image-valign-top uagb-infobox__outer-wrap\"><div class=\"uagb-ifb-content\"><div class=\"uagb-ifb-icon-wrap\"><svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 640 512\"><path d=\"M416 176C416 78.8 322.9 0 208 0S0 78.8 0 176c0 39.57 15.62 75.96 41.67 105.4c-16.39 32.76-39.23 57.32-39.59 57.68c-2.1 2.205-2.67 5.475-1.441 8.354C1.9 350.3 4.602 352 7.66 352c38.35 0 70.76-11.12 95.74-24.04C134.2 343.1 169.8 352 208 352C322.9 352 416 273.2 416 176zM599.6 443.7C624.8 413.9 640 376.6 640 336C640 238.8 554 160 448 160c-.3145 0-.6191 .041-.9336 .043C447.5 165.3 448 170.6 448 176c0 98.62-79.68 181.2-186.1 202.5C282.7 455.1 357.1 512 448 512c33.69 0 65.32-8.008 92.85-21.98C565.2 502 596.1 512 632.3 512c3.059 0 5.76-1.725 7.02-4.605c1.229-2.879 .6582-6.148-1.441-8.354C637.6 498.7 615.9 475.3 599.6 443.7z\"><\/path><\/svg><\/div><div class=\"uagb-ifb-title-wrap\"><h3 class=\"uagb-ifb-title\">Let&#8217;s talk!<\/h3><\/div><p class=\"uagb-ifb-desc\">Hey! If you like tech content, follow me:<\/p><\/div><\/div>\n\n\n\n<ul class=\"wp-block-social-links has-visible-labels is-style-default is-horizontal is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-ef5ce59c wp-block-social-links-is-layout-flex\"><li class=\"wp-social-link wp-social-link-twitter  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/twitter.com\/felipe_elia\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">felipe_elia<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-linkedin  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.linkedin.com\/in\/felipeelia\/\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">LinkedIn<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-github  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/felipeelia\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">felipeelia<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-instagram  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.instagram.com\/felipe.elia\/\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M12,4.622c2.403,0,2.688,0.009,3.637,0.052c0.877,0.04,1.354,0.187,1.671,0.31c0.42,0.163,0.72,0.358,1.035,0.673 c0.315,0.315,0.51,0.615,0.673,1.035c0.123,0.317,0.27,0.794,0.31,1.671c0.043,0.949,0.052,1.234,0.052,3.637 s-0.009,2.688-0.052,3.637c-0.04,0.877-0.187,1.354-0.31,1.671c-0.163,0.42-0.358,0.72-0.673,1.035 c-0.315,0.315-0.615,0.51-1.035,0.673c-0.317,0.123-0.794,0.27-1.671,0.31c-0.949,0.043-1.233,0.052-3.637,0.052 s-2.688-0.009-3.637-0.052c-0.877-0.04-1.354-0.187-1.671-0.31c-0.42-0.163-0.72-0.358-1.035-0.673 c-0.315-0.315-0.51-0.615-0.673-1.035c-0.123-0.317-0.27-0.794-0.31-1.671C4.631,14.688,4.622,14.403,4.622,12 s0.009-2.688,0.052-3.637c0.04-0.877,0.187-1.354,0.31-1.671c0.163-0.42,0.358-0.72,0.673-1.035 c0.315-0.315,0.615-0.51,1.035-0.673c0.317-0.123,0.794-0.27,1.671-0.31C9.312,4.631,9.597,4.622,12,4.622 M12,3 C9.556,3,9.249,3.01,8.289,3.054C7.331,3.098,6.677,3.25,6.105,3.472C5.513,3.702,5.011,4.01,4.511,4.511 c-0.5,0.5-0.808,1.002-1.038,1.594C3.25,6.677,3.098,7.331,3.054,8.289C3.01,9.249,3,9.556,3,12c0,2.444,0.01,2.751,0.054,3.711 c0.044,0.958,0.196,1.612,0.418,2.185c0.23,0.592,0.538,1.094,1.038,1.594c0.5,0.5,1.002,0.808,1.594,1.038 c0.572,0.222,1.227,0.375,2.185,0.418C9.249,20.99,9.556,21,12,21s2.751-0.01,3.711-0.054c0.958-0.044,1.612-0.196,2.185-0.418 c0.592-0.23,1.094-0.538,1.594-1.038c0.5-0.5,0.808-1.002,1.038-1.594c0.222-0.572,0.375-1.227,0.418-2.185 C20.99,14.751,21,14.444,21,12s-0.01-2.751-0.054-3.711c-0.044-0.958-0.196-1.612-0.418-2.185c-0.23-0.592-0.538-1.094-1.038-1.594 c-0.5-0.5-1.002-0.808-1.594-1.038c-0.572-0.222-1.227-0.375-2.185-0.418C14.751,3.01,14.444,3,12,3L12,3z M12,7.378 c-2.552,0-4.622,2.069-4.622,4.622S9.448,16.622,12,16.622s4.622-2.069,4.622-4.622S14.552,7.378,12,7.378z M12,15 c-1.657,0-3-1.343-3-3s1.343-3,3-3s3,1.343,3,3S13.657,15,12,15z M16.804,6.116c-0.596,0-1.08,0.484-1.08,1.08 s0.484,1.08,1.08,1.08c0.596,0,1.08-0.484,1.08-1.08S17.401,6.116,16.804,6.116z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">felipe.elia<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-facebook  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.facebook.com\/felipeeliawp\" class=\"wp-block-social-link-anchor\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z\"><\/path><\/svg><span class=\"wp-block-social-link-label\">Facebook<\/span><\/a><\/li><\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"o-que-eu-preciso-para-usar-object-cache-com-redis-no-wordpress\">What do I need to use WordPress Object Cache with Redis?<\/h3>\n\n\n\n<p>The requirements to use WordPress Object Cache with Redis are quite simple:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A WordPress website<\/li>\n\n\n\n<li>Redis running in your infrastructure<\/li>\n\n\n\n<li>A WordPress plugin to connect WP to Redis<\/li>\n<\/ul>\n\n\n\n<p>The best way to have step #2 done is to contact your hosting provider. On Cloudways, for example, you need to <a href=\"https:\/\/www.cloudways.com\/blog\/install-redis-cache-wordpress\/#activating-redis-on-the-cloudways-platform\">click on a button on their Dashboard to install Redis<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><a href=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2021\/08\/como-habilitar-redis-na-cloudways.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"478\" src=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2021\/08\/como-habilitar-redis-na-cloudways.jpg\" alt=\"How to install Redis on Cloudways: Server Management -&gt; Settings &amp; Packages -&gt; Packages -&gt; Redis (Install)\" class=\"wp-image-1963\" style=\"width:512px;height:239px\" srcset=\"https:\/\/felipeelia.com\/wp-content\/uploads\/2021\/08\/como-habilitar-redis-na-cloudways.jpg 1024w, https:\/\/felipeelia.com\/wp-content\/uploads\/2021\/08\/como-habilitar-redis-na-cloudways-300x140.jpg 300w, https:\/\/felipeelia.com\/wp-content\/uploads\/2021\/08\/como-habilitar-redis-na-cloudways-768x359.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"o-plugin-redis-object-cache\">The <em>Redis Object Cache<\/em> WordPress plugin<\/h2>\n\n\n\n<p>As I said in the other post, the plugin I use is <a href=\"https:\/\/wordpress.org\/plugins\/redis-cache\/\">Redis Object Cache<\/a>. Install and configure it is not hard. Out of the box, it will try to connect to a Redis instance in the same server (<code>127.0.0.1<\/code>) on port <code>6379<\/code> using Redis database number <code>0<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><a href=\"https:\/\/br.wordpress.org\/plugins\/redis-cache\/\"><img loading=\"lazy\" decoding=\"async\" width=\"959\" height=\"431\" src=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/06\/redis-object-cache-plugin.png\" alt=\"Screenshot of the &quot;Redis Object Cache&quot; plugin in WordPress.org Directory.\" class=\"wp-image-2048\" style=\"width:480px;height:216px\" srcset=\"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/06\/redis-object-cache-plugin.png 959w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/06\/redis-object-cache-plugin-300x135.png 300w, https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/06\/redis-object-cache-plugin-768x345.png 768w\" sizes=\"auto, (max-width: 959px) 100vw, 959px\" \/><\/a><\/figure>\n\n\n\n<p>To have the plugin working, it will need to copy its <code>object-cache.php<\/code> file from its own <em>includes<\/em> folder to the <em>wp-content<\/em> folder of your WordPress installation. If for whatever reason like directory permissions, it is not possible to copy the file automatically, you will need to copy it manually.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mesmo-redis-com-diferentes-sites-no-mesmo-servidor\">Same Redis for different sites at the same server<\/h3>\n\n\n\n<p>I have another blog running on this same server, sharing the same Redis installation. To avoid conflicts between stored information for each site, I had to define  <code>define( 'WP_REDIS_DATABASE', 0 );<\/code> on one and <code>define( 'WP_REDIS_DATABASE', 1 );<\/code> on the other.<\/p>\n\n\n\n<p>To adjust the configuration you will need to place some constants in your <em>wp-config.php<\/em> file. The full list of settings is available on the <a href=\"https:\/\/github.com\/rhubarbgroup\/redis-cache\/wiki\/Connection-Parameters\">plugin wiki<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"como-o-plugin-de-object-cache-funciona\">How the <em>Object Cache <\/em>plugin works<\/h2>\n\n\n\n<p>Inside the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_start_object_cache\/\">wp_start_object_cache()<\/a> function (see below), executed at the beginning of WordPress load flow, WP will detect if there is an <code>object-cache.php<\/code> drop-in or not. If it is available, the file is loaded, otherwise, the default implementation is used. After that, the cache is initiated.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#E6E6E6;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(243, 218, 218, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2f2f2f;color:#d9d9d9\">PHP<\/span><span role=\"button\" tabindex=\"0\" data-code=\"function wp_start_object_cache() {\n\t...\n\t\tif ( file_exists( WP_CONTENT_DIR . '\/object-cache.php' ) ) {\n\t\t\trequire_once WP_CONTENT_DIR . '\/object-cache.php';\n\t\t\t...\n\t\t}\n\t...\n \n\n\t\/\/ If there is no external cache, loads WP's.\n\tif ( ! wp_using_ext_object_cache() ) {\n\t\trequire_once ABSPATH . WPINC . '\/cache.php';\n \t}\n \n\trequire_once ABSPATH . WPINC . '\/cache-compat.php';\n \n\t...\n\twp_cache_init();\n\t...\n}\" style=\"color:#E6E6E6;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki slack-dark\" style=\"background-color: #222222\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_start_object_cache<\/span><span style=\"color: #E6E6E6\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #E6E6E6\"> ( <\/span><span style=\"color: #DCDCAA\">file_exists<\/span><span style=\"color: #E6E6E6\">( WP_CONTENT_DIR <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;\/object-cache.php&#39;<\/span><span style=\"color: #E6E6E6\"> ) ) {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">\t\t\t<\/span><span style=\"color: #C586C0\">require_once<\/span><span style=\"color: #E6E6E6\"> WP_CONTENT_DIR <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;\/object-cache.php&#39;<\/span><span style=\"color: #E6E6E6\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\"> <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #6A9955\">\/\/ If there is no external cache, loads WP&#39;s.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #E6E6E6\"> ( <\/span><span style=\"color: #D4D4D4\">!<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_using_ext_object_cache<\/span><span style=\"color: #E6E6E6\">() ) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #C586C0\">require_once<\/span><span style=\"color: #E6E6E6\"> ABSPATH <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> WPINC <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;\/cache.php&#39;<\/span><span style=\"color: #E6E6E6\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\"> \t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #C586C0\">require_once<\/span><span style=\"color: #E6E6E6\"> ABSPATH <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> WPINC <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;\/cache-compat.php&#39;<\/span><span style=\"color: #E6E6E6\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #DCDCAA\">wp_cache_init<\/span><span style=\"color: #E6E6E6\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><em>Redis Object Cache<\/em>&#8216;s <code>object-cache.php<\/code> contents can be seen <a href=\"https:\/\/plugins.trac.wordpress.org\/browser\/redis-cache\/trunk\/includes\/object-cache.php\">here<\/a>. It is formed by an implementation of the <code>WP_Object_Cache<\/code> class (last part of the file) and the several functions that use it like <code>wp_cache_add<\/code>, <code>wp_cache_get<\/code>, and  <code>wp_cache_delete<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><a href=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/doc-back-to-the-future-ready.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"360\" src=\"https:\/\/felipeelia.com\/br\/wp-content\/uploads\/2022\/08\/doc-back-to-the-future-ready.webp\" alt=\"Animated GIF of Doc Brown from &quot;Back to the Future&quot; holding electric cables and saying &quot;Ready!&quot;\" class=\"wp-image-2102\" style=\"width:360px;height:270px\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dando-uma-olhada-em-codigo\">Let&#8217;s give a look at some code<\/h2>\n\n\n\n<p>If you need some code to understand things better that is okay, I am one of those too. Here is a part of the code executed when you call <code>get_post( 123 );<\/code> in WordPress 6.0.1.<\/p>\n\n\n\n<p>The code starts in <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/6.0.1\/wp-includes\/post.php#L990\">wp-includes\/post.php<\/a>, where get_post calls <code>WP_Post::get_instance( $post )<\/code>.<\/p>\n\n\n\n<p>Then, in <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/6.0.1\/wp-includes\/class-wp-post.php#L231\">wp-includes\/class-wp-post.php<\/a>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#E6E6E6;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(243, 218, 218, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2f2f2f;color:#d9d9d9\">PHP<\/span><span role=\"button\" tabindex=\"0\" data-code=\"final class WP_Post {\n\t...\n\tpublic static function get_instance( $post_id ) {\n\t\t$_post = wp_cache_get( $post_id, 'posts' );\n\n\t\tif ( ! $_post ) {\n\t\t\t...\n\t\t\twp_cache_add( $_post-&gt;ID, $_post, 'posts' );\n\t\t} \n\t\t...\n\t}\n}\" style=\"color:#E6E6E6;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki slack-dark\" style=\"background-color: #222222\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">final<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #569CD6\">class<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #4EC9B0\">WP_Post<\/span><span style=\"color: #E6E6E6\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #569CD6\">static<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">get_instance<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$post_id<\/span><span style=\"color: #E6E6E6\"> ) {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #9CDCFE\">$_post<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_cache_get<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$post_id<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #CE9178\">&#39;posts&#39;<\/span><span style=\"color: #E6E6E6\"> );<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #E6E6E6\"> ( <\/span><span style=\"color: #D4D4D4\">!<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #9CDCFE\">$_post<\/span><span style=\"color: #E6E6E6\"> ) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">\t\t\t<\/span><span style=\"color: #DCDCAA\">wp_cache_add<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$_post<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #9CDCFE\">ID<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$_post<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #CE9178\">&#39;posts&#39;<\/span><span style=\"color: #E6E6E6\"> );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t} <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>At first, it checks if the cached value exists (<code>wp_cache_get<\/code>). If it exists it is used, otherwise, the post is fetched and then cached (<code>wp_cache_add<\/code>).<\/p>\n\n\n\n<p>If we look at the <code>wp_cache_add<\/code> function code, we can see it is nothing more than a simple wrapper for the <code>add<\/code> method of the <code>WP_Object_Cache<\/code> instance stored in the global variable <code>$wp_object_cache<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#E6E6E6;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2f2f2f;color:#d9d9d9\">PHP<\/span><span role=\"button\" tabindex=\"0\" data-code=\"function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {\n    global $wp_object_cache;\n \n    return $wp_object_cache-&gt;add( $key, $data, $group, (int) $expire );\n}\" style=\"color:#E6E6E6;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki slack-dark\" style=\"background-color: #222222\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_cache_add<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$data<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;&#39;<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$expire<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #E6E6E6\"> ) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">    <\/span><span style=\"color: #569CD6\">global<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #9CDCFE\">$wp_object_cache<\/span><span style=\"color: #E6E6E6\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #9CDCFE\">$wp_object_cache<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">add<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$data<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\">, (<\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #E6E6E6\">) <\/span><span style=\"color: #9CDCFE\">$expire<\/span><span style=\"color: #E6E6E6\"> );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"as-funcoes-de-cache-disponiveis-no-wordpress\">Cache functions available in  WordPress<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_object_cache\/#wp_cache-functions\">official documentation lists some of the most important cache functions<\/a> and I am transcribing them here. WordPress&#8217;s core itself uses them in several places but you can call them too in your theme or plugin.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#E6E6E6;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2f2f2f;color:#d9d9d9\">PHP<\/span><span role=\"button\" tabindex=\"0\" data-code=\"wp_cache_add( $key, $data, $group = '', $expire = 0 ) \/\/ If exists, do not overwrite\nwp_cache_set( $key, $data, $group = '', $expire = 0 ) \/\/ If exists, overwrite\nwp_cache_replace( $key, $data, $group, $expire ) \/\/ If does not exist, do nothing\nwp_cache_get( $key, $group = '', $force = false, $found = null )\nwp_cache_delete( $key, $group = '' )\nwp_cache_flush()\" style=\"color:#E6E6E6;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki slack-dark\" style=\"background-color: #222222\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_add<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$data<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;&#39;<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$expire<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #E6E6E6\"> ) <\/span><span style=\"color: #6A9955\">\/\/ If exists, do not overwrite<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_set<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$data<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;&#39;<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$expire<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #E6E6E6\"> ) <\/span><span style=\"color: #6A9955\">\/\/ If exists, overwrite<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_replace<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$data<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$expire<\/span><span style=\"color: #E6E6E6\"> ) <\/span><span style=\"color: #6A9955\">\/\/ If does not exist, do nothing<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_get<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;&#39;<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$force<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #569CD6\">false<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$found<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #569CD6\">null<\/span><span style=\"color: #E6E6E6\"> )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_delete<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$key<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #9CDCFE\">$group<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #CE9178\">&#39;&#39;<\/span><span style=\"color: #E6E6E6\"> )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">wp_cache_flush<\/span><span style=\"color: #E6E6E6\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"chave-valor-grupo-e-expiracao\">Key, value, group, and expiration<\/h3>\n\n\n\n<p>Most of the <code>wp_cache_*<\/code> functions use four parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Key:<\/strong> the identifier for the object stored in cache. The post ID, for example.<\/li>\n\n\n\n<li><strong>Value:<\/strong> the object stored in cache. In our example, the post.<\/li>\n\n\n\n<li><strong>Group (optional):<\/strong> You can optionally group values. Previously, it was used simply to organize things but coming in WordPress 6.1, there will be a <a href=\"https:\/\/core.trac.wordpress.org\/ticket\/4476\">new <code>wp_cache_flush_group<\/code> function<\/a> to flush all objects of a certain group. You will be able, for example, to delete just keys of a certain plugin.<\/li>\n\n\n\n<li><strong>Expiration (optional):<\/strong> for how long a cached value should be considered valid. Let&#8217;s give it a closer look now.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"expiracao\">Expiration<\/h3>\n\n\n\n<p>When we talk about cache, one of the most important concepts is expiration. <strong>Is the information we have still valid?<\/strong> This is a key part of any cache implementation, including WordPress Object Cache.<\/p>\n\n\n\n<p>So, how do we decide for how long a cached object should be considered valid?<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"baseado-em-um-evento\">Event-driven<\/h4>\n\n\n\n<p>Let&#8217;s say you are caching the list of posts of the biggest content. You get all the posts, apply the <code>the_content<\/code> filter in all of them, and check how many characters they have. Pretty intensive, right? This deserves to be cached.<\/p>\n\n\n\n<p><strong>What can change the result of this process? Only if a post is created, deleted, or edited, right?<\/strong><\/p>\n\n\n\n<p>In this case, our cache does not need to expire. <strong>It is enough to invalidate the result we have using a related <a href=\"https:\/\/felipeelia.com\/br\/o-que-sao-hooks\/\">hook<\/a><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"baseado-em-tempo\">Time-driven<\/h4>\n\n\n\n<p>If what you are caching comes, for example, from something external like an API, <strong>the event that invalidates the cache is not under our control<\/strong>. In this case, we need to <strong>check the results from time to time<\/strong> in the external API and update the value we have stored.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"transients-api-e-object-cache\">Transients API and Object Cache<\/h2>\n\n\n\n<p>If you read the post or watched the YouTube video about the <a href=\"https:\/\/felipeelia.com\/br\/cache-facil-no-wordpress-transients-api\/\">WordPress Transients API<\/a>, the central idea here is not new: <strong>a key-value pair that avoids a long process is the essential idea behind both things<\/strong>. In fact, in a certain aspect, it is indeed the same thing. Look at the implementation of the <code>get_transient<\/code> function:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#E6E6E6;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(243, 218, 218, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2f2f2f;color:#d9d9d9\">PHP<\/span><span role=\"button\" tabindex=\"0\" data-code=\"function get_transient( $transient ) {\n    if ( wp_using_ext_object_cache() || wp_installing() ) {\n        $value = wp_cache_get( $transient, 'transient' );\n    } else {\n\t\t...\n    }\n\t...\n}\" style=\"color:#E6E6E6;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki slack-dark\" style=\"background-color: #222222\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">get_transient<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$transient<\/span><span style=\"color: #E6E6E6\"> ) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">    <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #E6E6E6\"> ( <\/span><span style=\"color: #DCDCAA\">wp_using_ext_object_cache<\/span><span style=\"color: #E6E6E6\">() <\/span><span style=\"color: #D4D4D4\">||<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_installing<\/span><span style=\"color: #E6E6E6\">() ) {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E6E6E6\">        <\/span><span style=\"color: #9CDCFE\">$value<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #E6E6E6\"> <\/span><span style=\"color: #DCDCAA\">wp_cache_get<\/span><span style=\"color: #E6E6E6\">( <\/span><span style=\"color: #9CDCFE\">$transient<\/span><span style=\"color: #E6E6E6\">, <\/span><span style=\"color: #CE9178\">&#39;transient&#39;<\/span><span style=\"color: #E6E6E6\"> );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">    } <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #E6E6E6\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">\t<\/span><span style=\"color: #D4D4D4\">...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E6E6E6\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Basically, if you are using an external mechanism for Object Caching, the transient will be stored there. Otherwise, the regular database will be used. Interesting, huh? Make sure to check that content too!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!<\/p>\n","protected":false},"author":1,"featured_media":2151,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[91],"tags":[155,160,157,162],"class_list":["post-2159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-en","tag-api-en","tag-cache-en","tag-php-en","tag-wordpress-en","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WordPress, Object Cache, and Redis | Felipe Elia<\/title>\n<meta name=\"description\" content=\"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress, Object Cache, and Redis | Felipe Elia\" \/>\n<meta property=\"og:description\" content=\"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/\" \/>\n<meta property=\"og:site_name\" content=\"Felipe Elia\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-13T19:17:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-05T22:43:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Felipe Elia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/felipe_elia\" \/>\n<meta name=\"twitter:site\" content=\"@felipe_elia\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Felipe Elia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/\"},\"author\":{\"name\":\"Felipe Elia\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#\\\/schema\\\/person\\\/1ff49bb0ede58bc73cb5b8caf7afc6b0\"},\"headline\":\"WordPress, Object Cache, and Redis\",\"datePublished\":\"2022-08-13T19:17:01+00:00\",\"dateModified\":\"2024-08-05T22:43:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/\"},\"wordCount\":1517,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#\\\/schema\\\/person\\\/1ff49bb0ede58bc73cb5b8caf7afc6b0\"},\"image\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/wordpress-object-cache-and-redis.jpg\",\"keywords\":[\"API\",\"Cache\",\"PHP\",\"WordPress\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/\",\"url\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/\",\"name\":\"WordPress, Object Cache, and Redis | Felipe Elia\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/wordpress-object-cache-and-redis.jpg\",\"datePublished\":\"2022-08-13T19:17:01+00:00\",\"dateModified\":\"2024-08-05T22:43:42+00:00\",\"description\":\"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#primaryimage\",\"url\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/wordpress-object-cache-and-redis.jpg\",\"contentUrl\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/wordpress-object-cache-and-redis.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wordpress-object-cache-and-redis\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\\\/\\\/felipeelia.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress, Object Cache, and Redis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#website\",\"url\":\"https:\\\/\\\/felipeelia.com\\\/\",\"name\":\"Felipe Elia\",\"description\":\"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado\",\"publisher\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#\\\/schema\\\/person\\\/1ff49bb0ede58bc73cb5b8caf7afc6b0\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/felipeelia.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/felipeelia.com\\\/#\\\/schema\\\/person\\\/1ff49bb0ede58bc73cb5b8caf7afc6b0\",\"name\":\"Felipe Elia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/avatar-400x400-1.jpg\",\"url\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/avatar-400x400-1.jpg\",\"contentUrl\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/avatar-400x400-1.jpg\",\"width\":400,\"height\":400,\"caption\":\"Felipe Elia\"},\"logo\":{\"@id\":\"https:\\\/\\\/felipeelia.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/avatar-400x400-1.jpg\"},\"description\":\"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/felipe.elia\",\"https:\\\/\\\/www.instagram.com\\\/felipe.elia\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/felipeelia\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/felipe_elia\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCD_26rOE3ClALcZreTkyIoQ\"],\"url\":\"https:\\\/\\\/felipeelia.com\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress, Object Cache, and Redis | Felipe Elia","description":"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!","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:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/","og_locale":"pt_BR","og_type":"article","og_title":"WordPress, Object Cache, and Redis | Felipe Elia","og_description":"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!","og_url":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/","og_site_name":"Felipe Elia","article_publisher":"https:\/\/www.facebook.com\/felipe.elia","article_author":"https:\/\/www.facebook.com\/felipe.elia","article_published_time":"2022-08-13T19:17:01+00:00","article_modified_time":"2024-08-05T22:43:42+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg","type":"image\/jpeg"}],"author":"Felipe Elia","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/felipe_elia","twitter_site":"@felipe_elia","twitter_misc":{"Escrito por":"Felipe Elia","Est. tempo de leitura":"19 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#article","isPartOf":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/"},"author":{"name":"Felipe Elia","@id":"https:\/\/felipeelia.com\/#\/schema\/person\/1ff49bb0ede58bc73cb5b8caf7afc6b0"},"headline":"WordPress, Object Cache, and Redis","datePublished":"2022-08-13T19:17:01+00:00","dateModified":"2024-08-05T22:43:42+00:00","mainEntityOfPage":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/"},"wordCount":1517,"commentCount":0,"publisher":{"@id":"https:\/\/felipeelia.com\/#\/schema\/person\/1ff49bb0ede58bc73cb5b8caf7afc6b0"},"image":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg","keywords":["API","Cache","PHP","WordPress"],"articleSection":["WordPress"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/","url":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/","name":"WordPress, Object Cache, and Redis | Felipe Elia","isPartOf":{"@id":"https:\/\/felipeelia.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#primaryimage"},"image":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg","datePublished":"2022-08-13T19:17:01+00:00","dateModified":"2024-08-05T22:43:42+00:00","description":"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!","breadcrumb":{"@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#primaryimage","url":"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg","contentUrl":"https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/felipeelia.com\/wordpress-object-cache-and-redis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/felipeelia.com\/"},{"@type":"ListItem","position":2,"name":"WordPress, Object Cache, and Redis"}]},{"@type":"WebSite","@id":"https:\/\/felipeelia.com\/#website","url":"https:\/\/felipeelia.com\/","name":"Felipe Elia","description":"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado","publisher":{"@id":"https:\/\/felipeelia.com\/#\/schema\/person\/1ff49bb0ede58bc73cb5b8caf7afc6b0"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/felipeelia.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":["Person","Organization"],"@id":"https:\/\/felipeelia.com\/#\/schema\/person\/1ff49bb0ede58bc73cb5b8caf7afc6b0","name":"Felipe Elia","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/felipeelia.com\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","url":"https:\/\/felipeelia.com\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","contentUrl":"https:\/\/felipeelia.com\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","width":400,"height":400,"caption":"Felipe Elia"},"logo":{"@id":"https:\/\/felipeelia.com\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg"},"description":"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.","sameAs":["https:\/\/www.facebook.com\/felipe.elia","https:\/\/www.instagram.com\/felipe.elia\/","https:\/\/www.linkedin.com\/in\/felipeelia\/","https:\/\/x.com\/https:\/\/twitter.com\/felipe_elia","https:\/\/www.youtube.com\/channel\/UCD_26rOE3ClALcZreTkyIoQ"],"url":"https:\/\/felipeelia.com\/author\/admin\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg",1920,1080,false],"thumbnail":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-150x150.jpg",150,150,true],"medium":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-300x169.jpg",300,169,true],"medium_large":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-768x432.jpg",768,432,true],"large":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-1536x864.jpg",1536,864,true],"2048x2048":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg",1920,1080,false],"ocean-thumb-m":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg",600,338,false],"ocean-thumb-ml":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg",800,450,false],"ocean-thumb-l":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis.jpg",1200,675,false],"yarpp-thumbnail":["https:\/\/felipeelia.com\/wp-content\/uploads\/2022\/08\/wordpress-object-cache-and-redis-120x120.jpg",120,120,true]},"uagb_author_info":{"display_name":"Felipe Elia","author_link":"https:\/\/felipeelia.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Check how WordPress Object Cache and Redis can make your website faster while leveling up your WP programming skills!","_links":{"self":[{"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/posts\/2159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/comments?post=2159"}],"version-history":[{"count":1,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/posts\/2159\/revisions"}],"predecessor-version":[{"id":3270,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/posts\/2159\/revisions\/3270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/media\/2151"}],"wp:attachment":[{"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/media?parent=2159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/categories?post=2159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/felipeelia.com\/wp-json\/wp\/v2\/tags?post=2159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}