Skip to content

feat(cache): support stale while revalidate#1269

Merged
innocenzi merged 2 commits into
tempestphp:mainfrom
innocenzi:feat/cache-stale-while-revalidate
May 23, 2025
Merged

feat(cache): support stale while revalidate#1269
innocenzi merged 2 commits into
tempestphp:mainfrom
innocenzi:feat/cache-stale-while-revalidate

Conversation

@innocenzi

Copy link
Copy Markdown
Member

This pull request adds support for the "stale while invalidate" pattern on the cache implementation.

$cache->resolve(
    key: 'cache-key',
    callback: fn () => $this->computeExpensiveValue(),
    expiration: Duration::minute(), // should expire in a minute
    stale: Duration::minute() // but allow a stale period of one more minute
);

When requested in the stale window (in this example, from one minute to two minutes after caching the value), a deferred callback will be registered for refreshing the value.

@innocenzi innocenzi merged commit dde685a into tempestphp:main May 23, 2025
76 of 77 checks passed
@innocenzi innocenzi deleted the feat/cache-stale-while-revalidate branch May 23, 2025 15:37
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

Successfully merging this pull request may close these issues.

1 participant