litespeedtech / litespeedtech/lscache-drupal

Feature Request: Vary cache based on Drupal user roles

Open
#32 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
15
Forks
19
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing how the Drupal module currently sets _lscache_vary for authenticated users, then compare the requested behavior with the linked Advanced Varnish documentation. Done should mean site administrators can configure role-based cache variation, excluded roles are not cached, and role cache values are removed on logout.

Written by the indexing model from the issue text.

Assessment

Tech stack
drupal, php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.