{"id":8046,"date":"2017-09-13T06:00:21","date_gmt":"2017-09-13T10:00:21","guid":{"rendered":"https:\/\/blog.litespeedtech.com\/?p=8046"},"modified":"2017-09-13T06:00:21","modified_gmt":"2017-09-13T10:00:21","slug":"wpw-vary-groups","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2017\/09\/13\/wpw-vary-groups\/","title":{"rendered":"WpW: Vary Groups"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/09\/null-4.jpeg\" 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>!<\/p>\n<p>It\u2019s been a busy few weeks for <a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\">LiteSpeed Cache for WordPress<\/a>! We\u2019ve released updates that have enabled <a href=\"https:\/\/lswp.store\/2017\/08\/30\/wpw-private-cache-vs-public-cache\/\">private cache<\/a> and <a href=\"https:\/\/lswp.store\/?p=8004\">ESI<\/a>, both of which have been high on our customers\u2019 wish lists. <strong>Today we\u2019re going to talk about another feature that was enabled recently: Vary Groups.<\/strong><\/p>\n<p>The Vary Group functionality combines the concepts of \u201ccache varies\u201d and \u201cuser roles.\u201d Let\u2019s explore each of those ideas and then see what happens when you put them together.<\/p>\n<h2>Cache Varies<\/h2>\n<p>Sometimes you need to have multiple publicly-cached versions of a single page. We call this \u201cvarying,\u201d and it can be used on many types of criteria. One popular vary built into the plugin allows you to specify a list of mobile user agents so that we can cache one view for mobile users and a different view for those on desktop.<\/p>\n<h2>User Roles<\/h2>\n<p>WordPress comes with a handful of built-in user roles: administrator, author, editor, contributor, and subscriber. Various plugins may create other roles as necessary.<\/p>\n<p>Each of these roles gives a user certain permissions. Editors, for instance, can publish and manage the posts on a site, but they don\u2019t have access to all of the site-management features that an Administrator does.<\/p>\n<h2>Vary Groups<\/h2>\n<p>With Vary Groups you can have multiple publicly-cached versions of a single page, based on the permissions of the users who view the page.<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/09\/null-5.jpeg\" alt=\"\" width=\"672\" height=\"448\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>An Administrator has all kinds of abilities that the other users do not. They can edit and delete posts. They can manage categories, remove users, switch themes, and so on. In some themes, administrator functions will appear right on the public pages (like an \u201cedit\u201d link at the end of a post). If you create a Vary Group for administrators, then LSCache will save two public copies of the page: one with all of the editing permissions displayed on it for anyone in the administrator group, and the default copy of the page with none of the editing links for everyone else.<\/p>\n<p><strong>Here\u2019s a more complicated example:<\/strong><\/p>\n<p>You have a shop running on your site, and through the shop admin, you\u2019ve defined two user roles: <code>retail_customer<\/code> and <code>wholesale_customer<\/code>. You have two sets of prices, and three different ways that your site can be viewed: users in the group <code>retail_customers<\/code> will see your highest prices. Users in the group <code>wholesale_customers<\/code> will see your lowest prices. Users who are not yet customers will see the default page with no pricing whatsoever. To ensure that the three different views would be saved separately in the public cache, you would create two Vary Groups, one for each customer role.<\/p>\n<p><strong>An important distinction:<\/strong><\/p>\n<p>With Vary Groups, we\u2019re not changing the behavior of your application at all. We are simply allowing you to have separate cached copies for each of the public views that are already being generated. Before we had Vary Group functionality, you would only have been able to cache the default view, which usually meant that you couldn\u2019t cache pages at all for logged-in users. This new ability to cache all of your user-role-based content is a nice perk!<\/p>\n<h2>Setting it up<\/h2>\n<p>From your WordPress Admin, navigate to <strong>LiteSpeed Cache &gt; Settings &gt; ESI<\/strong>. Scroll down to the <strong>Vary Group<\/strong> setting.<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2017\/09\/null-6.jpeg\" alt=\"\" width=\"672\" height=\"536\" \/><\/p>\n<p>You should see a list of the user roles that are defined on your site. Your list of user roles may be different than our example site\u2019s list above, but don\u2019t let that confuse you. It\u2019s normal.<\/p>\n<p>To create a vary group for any user role shown, enter a non-zero value into the box next to that user role. If a user role has a <code>0<\/code> next to it, then it will be served the default cached copy.<\/p>\n<p>There is no significance to the numbers other than the fact that unique views should have unique values.<\/p>\n<p>If two user roles share the same view, put them in the same group by using the same number. In other words, if <code>author<\/code> and <code>editor<\/code> both have the same view, but it\u2019s different from everyone else\u2019s view, <code>author<\/code> and <code>editor<\/code> could both be given the number <code>22<\/code>, while everyone else remained at <code>0<\/code>.<\/p>\n<h2>Why?<\/h2>\n<p>You may be wondering, why do this when you can just use ESI to adjust what displays on different people\u2019s pages? Or cache the whole page in private cache?<\/p>\n<p>While ESI is handy for situations where you want to insert a little bit of private content onto a mostly-public page, it can be resource-intensive, particularly if several blocks are required on the page.<\/p>\n<p>Additionally, the situations that call for Vary Groups are not <em>quite<\/em> the same as those that benefit from ESI or private caching.<\/p>\n<p><strong>Use Vary Groups when your pages have multiple public versions that have been generated based on user permissions.<\/strong> The differences might be subtle, like on a shop page where the design is the same but the prices vary per user group. Or the differences might be drastic, going so far as to not show some content <em>at all<\/em> for certain user roles.<\/p>\n<p>With Vary Groups, we cache one copy of the page per group. This is different than privately-cached content, which is stored as one copy of the page for each user that requests it. When you privately cache a page, you can potentially be caching thousands of copies of the same page! Reserve private cache for pages that truly serve up individualized content that varies from user to user.<\/p>\n<p>Vary Groups are a useful tool in your cache toolbox. They use far fewer resources than private caches do, and are easier on the server than ESI is. If you have situations where different public content is being generated based on user roles, Vary Group functionality is your most efficient caching option.<\/p>\n<p><strong>If you have any questions about this, or are wondering what type of caching would benefit your unique situation, leave a comment and ask us!<\/strong><\/p>\n<p>&#8212;<\/p>\n<p>Have 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>If you have situations where different public content is being generated based on user roles, Vary Group functionality is your most efficient caching option.<\/p>\n","protected":false},"author":1,"featured_media":8138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[316,317],"class_list":["post-8046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cache","tag-wordpress","tag-wordpress-wednesday"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2017\/09\/wpw18.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/8046","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=8046"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/8046\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/8138"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=8046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=8046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=8046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}