{"id":8694,"date":"2017-12-13T04:00:23","date_gmt":"2017-12-13T08:00:23","guid":{"rendered":"https:\/\/blog.litespeedtech.com\/?p=8694"},"modified":"2017-12-13T04:00:23","modified_gmt":"2017-12-13T08:00:23","slug":"wpw-choosing-between-public-cache-private-cache-and-esi","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2017\/12\/13\/wpw-choosing-between-public-cache-private-cache-and-esi\/","title":{"rendered":"WpW: Choosing Between Public Cache, Private Cache, and ESI"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/null.png\" alt=\"\" width=\"640\" height=\"320\" \/><\/p>\n<p>Welcome to another installment of <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a>!<br \/>\nToday&#8217;s Topic:\u00a0<strong>When to Use Public Cache, Private Cache, or ESI<\/strong><\/p>\n<p><em><strong>Disclaimer<\/strong>: The information contained in this post is accurate for LSCWP v1.6.6 [<a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/#developers\">release log<\/a>]. If you are using a newer version of the plugin, some details may have changed. Please<a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:lscwp\"> refer to our wiki<\/a> for the latest!<\/em><\/p>\n<p>LiteSpeed Cache can store pages in a public cache, in private caches, and via ESI. (ESI = Edge Side Includes, which can essentially result in a public\/private hybrid.) Today we\u2019re going to visualize these three types of caching, and help you to figure out which one is best for <em>your<\/em> particular application.<\/p>\n<h2>Public Cache<\/h2>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/null-2.jpeg\" alt=\"\" width=\"672\" height=\"672\" \/><\/p>\n<p>For the sake of simplicity, let\u2019s say that you have a site with just one page on it, and that your site has four visitors.<\/p>\n<p>This piece of paper represents the page of your site as stored in public cache. All four visitors to your site\u2019s page are shown that exact same piece of paper.<\/p>\n<p><strong>PRO<\/strong>: Very little storage space is required.<br \/>\n<strong>CON<\/strong>: There\u2019s no opportunity for personalization &#8211; everyone gets the <em>exact same page<\/em>.<\/p>\n<p>Any page that has no personalized content whatsoever is a good candidate for public cache.<\/p>\n<p>A blog archive page, for instance, could work, if it has no Admin Bar at the top, and there are no areas on the page that say \u201cWelcome, Sally\u201d or anything of that kind. When Sally visits the page, she sees exactly the same content as Linus, Charlie, and Lucy do when they visit.<\/p>\n<p>Many simple sites do just fine with public cache. If you don\u2019t allow your visitors to create logins, and you don\u2019t create any special content based on data that you can learn from their IP address (for instance), the chances are very good that public cache will be adequate for your site.<\/p>\n<p>So what do you do if your visitors <em>can<\/em> create logins, or you <em>do<\/em> want to display the weather for their IP\u2019s city?<\/p>\n<p>You\u2019re going to need more paper for that.<\/p>\n<h2>Private Cache<\/h2>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/null-3.jpeg\" alt=\"\" width=\"672\" height=\"672\" \/><\/p>\n<p>When you have LSCache configured to save a page in private cache, it\u2019s as if you have a whole pile of papers, one for each visitor to that page.<\/p>\n<p><strong>PRO<\/strong>: You can personalize each paper to a great extent &#8211; different colors, different patterns, a completely different design if you like&#8230;<br \/>\n<strong>CON<\/strong>: A lot more space is required to store all of those individual pages.<\/p>\n<p>A classic example of data that should be cached privately is a shopping cart. You certainly do not want every visitor to your shop to be served the exact same shopping cart page. The contents of Sally\u2019s cart are bound to differ from the contents of Linus\u2019s cart.<\/p>\n<p>The simplest way to deal with this is to store the shopping cart page in private cache. Or, in terms of our paper metaphor, set aside a new piece of paper for each visitor who accesses the page.<\/p>\n<p>This is fairly simple to set up, but you have to be careful if you have storage limitations. It\u2019s not a big deal with our 4-person example, but if you have 10,000 visitors to one page, that\u2019s 10,000 copies of that page in private cache. It adds up!<\/p>\n<p>So, what if you have a page with only a very small amount of private content on it? Is there an alternative to storing thousands of copies of the full page, when it\u2019s only a tiny area of the page that is changing?<\/p>\n<p>Sure there is, and it\u2019s called ESI.<\/p>\n<h2>Public Cache with ESI Blocks<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/null-4.jpeg\" alt=\"\" width=\"672\" height=\"672\" \/><\/p>\n<p>When you use ESI (or, Edge Side Includes), you are storing the full page in public cache: a single piece of paper like we had earlier. The difference is that now you are punching holes where the private information needs to go, and caching those holes differently.<\/p>\n<p>When a visitor requests the page, they are served the one single page, but with their own set of special blocks plugging up the holes.<\/p>\n<p><strong>PROs<\/strong>: Very little space is required, and there\u2019s room for a small amount of personalization.<br \/>\n<strong>CON<\/strong>: It consumes more resources to show a visitor a page that needs to be assembled from several pieces than it does to show them a page that is already intact.<\/p>\n<p>Let\u2019s look at that shopping cart again. In many cases, the shopping cart block in the middle of the page is the only piece that differs from visitor to visitor. The header, the footer, a sidebar or two, and possibly some displayed shipping policies may be exactly the same for everyone. In this case, it could be better to keep serving the full page from public cache, but punch a hole in it for the private shopping cart contents.<\/p>\n<p>ESI is best used in situations where most of the page is public, but one or two sections of it are not. A personalized greeting, the aforementioned Admin Bar, a widget showing the visitor\u2019s recent activity\u2026 those are all things that can be put inside an ESI block and cached differently than the rest of the page.<\/p>\n<p>The biggest pitfall with using ESI is in using it too much on a single page. If you have many areas of private content on a page, the effort that the server must go through in order to reassemble the pieces can negate the caching benefits. For pages with a lot of private content, it\u2019s better just to cache the whole page privately.<\/p>\n<h2>What Type of Cache is Right for You?<\/h2>\n<p>As you can see, all three configurations have pros and cons associated with them. You\u2019ll need to look at your own site, and what you are trying to accomplish with it.<\/p>\n<p><a href=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-8706\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-1024x341.png\" alt=\"\" width=\"1024\" height=\"341\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-1024x341.png 1024w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-300x100.png 300w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-768x256.png 768w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-1320x440.png 1320w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d-600x200.png 600w, https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/wpw31d.png 1500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Can you get away with storing just a single page for everyone? Do you need to store a whole separate page for each of your visitors? Or can you use a single page with a few holes punched into it?<\/p>\n<p>Furthermore, does the same strategy apply to every page on your site, or can you cache some pages differently than others?<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Cache Type<\/strong><\/td>\n<td><strong>When to Use<\/strong><\/td>\n<td><strong>Examples<\/strong><\/td>\n<td><strong>Storage Space<\/strong><\/td>\n<td><strong>Resources<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Public<\/strong><\/td>\n<td>Page has only content that may be displayed to every visitor<\/td>\n<td>*Blog post page<br \/>\n*Blog archive page<br \/>\n*Product Information page<\/td>\n<td>Baseline<\/td>\n<td>Baseline<\/td>\n<\/tr>\n<tr>\n<td><strong>Private<\/strong><\/td>\n<td>Page has extensive customization, relevant only to individual visitors<\/td>\n<td>*User account page<br \/>\n*Shopping cart page<br \/>\n*Available downloads page<\/td>\n<td>Significantly more than Baseline<\/td>\n<td>About the same as Baseline<\/td>\n<\/tr>\n<tr>\n<td><strong>ESI<\/strong><\/td>\n<td>Page is mostly public with a few small areas of private content<\/td>\n<td>On otherwise-public page:<br \/>\n*Admin bar<br \/>\n*Recent posts widget<br \/>\n*Personal greeting<\/td>\n<td>Slightly more than Baseline<\/td>\n<td>Significantly more than Basline<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Keep in mind that the examples in the chart above are just that: examples. Even though \u201cblog post page\u201d is listed in the \u201cPublic\u201d row, there could certainly be situations where blog post pages contain areas of private content. It depends on the theme and configuration of the site.<\/p>\n<p>If you want to know more, take a look at these in-depth articles:<\/p>\n<ul>\n<li><a href=\"https:\/\/lswp.store\/2017\/08\/30\/wpw-private-cache-vs-public-cache\/\">Private Cache vs. Public Cache<\/a><\/li>\n<li><a href=\"https:\/\/lswp.store\/2017\/09\/06\/wpw-esi-and-litespeed-cache\/\">ESI and LiteSpeed Cache<\/a><\/li>\n<\/ul>\n<p>If you still can\u2019t decide which way to go, feel free to <a href=\"https:\/\/wordpress.org\/support\/plugin\/litespeed-cache\/\">post on our support forum<\/a>. LiteSpeed Cache is capable of handling public cache, private cache, <em>and<\/em> ESI, and we\u2019d be happy to help you figure it out!<\/p>\n<p>&#8212;<br \/>\nHave some of your own ideas for future <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\">WordPress Wednesday<\/a> topics? Leave us a comment!<\/p>\n<p>Don\u2019t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:<\/p>\n<ul>\n<li>Subscribe to the <a href=\"http:\/\/blog.litespeedtech.com\/tag\/wordpress-wednesday\/feed\/\">WordPress Wednesday RSS feed<\/a><\/li>\n<li>Download <a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\">LiteSpeed Cache for WordPress plugin<\/a><\/li>\n<li>Learn more about the plugin <a href=\"https:\/\/www.litespeedtech.com\/products\/cache-plugins\/wordpress-acceleration\">on our website<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn the pros and cons of each type of caching and determine what is right for your site.<\/p>\n","protected":false},"author":1,"featured_media":8696,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[103,316,317],"class_list":["post-8694","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cache","tag-esi","tag-wordpress","tag-wordpress-wednesday"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2017\/12\/null.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/8694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/comments?post=8694"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/8694\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/8696"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=8694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=8694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=8694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}