Page MenuHomePhabricator

On rendering an abstract fragment (currently via abstractwiki_run_fragment), consider not adding all three arguments to cache key
Closed, ResolvedPublic

Description

Description

An abstract content fragment has three top-level arguments:

  • Z825K1: Wikidata item reference
  • Z825K2: Current language
  • Z825K3: Today's date

When rendering an abstract content fragment we first check whether the fragment is already generated and cached. If not cached, we make a remote request to Wikifunctions wikilambda_function_call Action API.

While every fragment probably needs wikidata item and language to work, it is often the case that the date is not used. Also, because the date changes every day (🙄), this means that the cache value is no longer valid.

We should devise a system so that:

  • Fragments are not generated daily unnecessarily
  • Fragments can maybe fallback to a stored earlier date

Implementation details

Implementing Stale-While-Revalidate strategy:

  • Rendered fragments are stored with and without date
  • When requesting a fragment render via abstractwiki_run_fragment, we do:
    • check whether the fragment is cached for today's date; we return cached value and exit if that's the case.
    • if cache miss for today, check for a stored fragment without date
      • if there is stale content; we return the value and run an async job to revalidate the fragment and refresh the fresh and stale values
      • if there is no stale content; we run synchronous call to wikilambda_function_call, and store fragment under cache key with and without date

Stale fragment (cache entry without date) TTL_MONTH
Fresh fragment (cache entry with today's date) TTL_WEEK (we need it to stay at least 48 hours)


Desired behavior/Acceptance criteria

  • When an abstract fragment does not use the date argument, it should not be re-generated daily
  • When an abstract fragment uses the date argument, it can fallback to stored content from a previous date

Completion checklist

Event Timeline

Change #1239737 had a related patch set uploaded (by Genoveva Galarza; author: Genoveva Galarza):

[mediawiki/extensions/WikiLambda@master] Implement stale-while-revalidate cache strategy for Abstract Content fragment

https://gerrit.wikimedia.org/r/1239737

Change #1239737 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Implement stale-while-revalidate cache strategy for Abstract Content fragment

https://gerrit.wikimedia.org/r/1239737

Jdforrester-WMF changed the task status from Open to In Progress.Feb 18 2026, 6:44 PM
Jdforrester-WMF triaged this task as Medium priority.