litespeedtech / lscache-drupal

LSCache Plugin for Drupal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Vary cache based on Drupal user roles

yoyo-rk opened this issue · comments

Often different Drupal roles require different page contents. For instance, anonymous may require different content than authenticated and admin will require different content than both anonymous and authenticated. It is typical that admin should not be cached, but quite often pages for authenticated user roles are all the same for the role and so can be cached.

LSCache does not differentiate between authenticated and admin roles. When users authenticate, LSCache sets _lscache_vary to 'loggedin' no matter the user role, thus, unless private cache is set, pages are not cached for authenticated users. But for large sites with thousands or tens of thousands of users, private cache is untenable. Caching per user role will increase the number of cached pages, especially when there are multiple roles below the admin level, but will be more efficient than using private cache.

Preferably, LSCache Drupal module would support the feature of varying cache based on defined user roles, as by the site administrator.

Currently, this feature is supported with Varnish + Advanced Varnish Drupal module. For reference, the Advanced Varnish module allows site administrators to turn on cache for authenticated users. For example, when the user role 'authenticated' is allowed to cache, the Advanced Varnish Cache module sets two cookies: ADVINF and ADVBIN. The former specifies the roles the authenticated user possesses, while the latter specifies the appropriate cache bin for the user. The ADVBIN value varies depending on the user role such that all roles that should be cached have a unique bin value, i.e., if ADVINF=authenticated, ADVBIN=1234, but if ADVINF=authenticated_other, ADVBIN=5678. Thus the vary header says to look for the bin info in the cookie and serve the corresponding cached page for the role. When a role should not have pages cached for it, no ADVINF or ADVBIN cookies are set. On logout, if the cookies are set the values are deleted.

https://www.drupal.org/docs/contributed-modules/advanced-varnish/cache-for-authenticated-users
https://www.drupal.org/project/adv_varnish