Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Vary cache based on Drupal user roles #32

Open
yoyo-rk opened this issue May 13, 2023 · 0 comments
Open

Feature Request: Vary cache based on Drupal user roles #32

yoyo-rk opened this issue May 13, 2023 · 0 comments

Comments

@yoyo-rk
Copy link

yoyo-rk commented May 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant