Shared cache for user-independent pages: decorator, user-read guard, audit tooling

Open
#2,655 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
28/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python, redis

Research direction

Start with the design notes in #1360 and #695, then inspect library/django_utils/, the annotation-version switch, and the vg command entry point to understand the existing cache and tooling patterns. Trace user reads through views, templates, and template tags, including uicore/templatetags/ui_utils.py and ui_tabs_builder.py. Done means a shared cache can safely reject user-dependent responses, audit tooling can report user reads, and tests cover cross-user reuse and build-specific keys.

Written by the indexing model from the issue text.

Description

🤖 Written by Claude

Follow-on from #2007 (menus and the rest of the per-user page frame now load by ajax, so uicore/page/base.html reads nothing about the user) and the design notes on #1360 and #695. Those two issues are about public pages for anonymous users; this one is the infrastructure that lets a logged-in page whose body is user-independent be served from one shared cache entry.

Why cache_page can't do it. Django's LoginRequiredMiddleware evaluates request.user.is_authenticated before the view runs, which reads the session, and SessionMiddleware then adds Vary: Cookie. cache_page keys on the Vary headers, so on any login-required page it caches per session. Sharing across users needs an explicit key that ignores Vary, plus proof that the body is user-independent. That proof is the hard part: of the 96 templates extending base.html, 52 still read the user, and views reference request.user in some 620 places.

Proposed

  1. shared_page_cache(key_fn, timeout) in library/django_utils/: explicit key (path, genome build, a bumpable version counter), ignores Vary. During the view it wraps request.user in a recording proxy and refuses to store, with a log line, if the view or its templates read the user. ("Session accessed" is no longer a usable signal because the middleware has already evaluated the lazy user.)
  2. A version counter in Redis bumped by the annotation-version switch, with a management command to bump it by hand; a warmer task for the top-N objects by hit count is optional.
  3. vg page <url> --user-reads: lists where the view and templates read the user, so auditing a candidate page is mechanical. uicore/templatetags/ui_utils.py and ui_tabs_builder.py read request.user for admin-only tags, so the report has to cover template tags too.
  4. First candidates whose bodies are already user-free or nearly so: view_gene_symbol (its annotation description already passes user=None so it can be cached globally), transcript and gene version pages, ontology term pages, the annotation versions and evidence keys reference pages. Per-user sections become ajax fragments, which is the same porting #1360 needs.
  5. Pages that stay user-specific keep cache_page + vary_on_cookie where a per-session cache is still a win (analysis/views/views_grid.py already does this).

Fragment caching (#2654) is the cheaper first step and should land first; this issue is for the pages where the whole body can be shared. #1360 is this issue's first consumer for anonymous users.

Tests worth keeping: the decorator refuses a response whose view read the user; two requests for one path from different users hit the cache once; one path on two builds is two entries.

Dominant language
Python
Stars
31
Forks
4
Avg merge
4h 52m
Merged PRs (30d)
183

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from SACGF/variantgrid

All issues in SACGF/variantgrid

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.