CachePolicy
How long, and to whom, a server's answers may be cached (SEP-2549).
The default says "do not cache": ttlMs: 0 and private. That is the honest
answer for a server nobody has told us about — public lets a shared proxy
serve one caller's answer to another, which is a disclosure decision only the
operator can make.
Granularity is per method, because that is what the caching hint describes: a
tools/list is usually identical for everyone and worth a long public TTL,
while a resources/read usually is not.
Tags
Table of Contents
Properties
- $perMethod : array<string|int, mixed>
- $scope : CacheScope
- $ttlMs : int
Methods
- default() : self
- none() : self
- The conservative default: nothing is fresh, nothing is shared.
- scopeFor() : CacheScope
- ttlFor() : int
- withMethod() : self
- Overrides the policy for one method.
- __construct() : mixed
Properties
$perMethod read-only
private
array<string|int, mixed>
$perMethod
= []
$scope read-only
private
CacheScope
$scope
$ttlMs read-only
private
int
$ttlMs
Methods
default()
public
static default(int $ttlMs[, CacheScope $scope = CacheScope::Private ]) : self
Parameters
- $ttlMs : int
-
how long an answer stays fresh, in milliseconds
- $scope : CacheScope = CacheScope::Private
Return values
selfnone()
The conservative default: nothing is fresh, nothing is shared.
public
static none() : self
Return values
selfscopeFor()
public
scopeFor(string $method) : CacheScope
Parameters
- $method : string
Return values
CacheScopettlFor()
public
ttlFor(string $method) : int
Parameters
- $method : string
Return values
intwithMethod()
Overrides the policy for one method.
public
withMethod(string $method, int $ttlMs[, CacheScope $scope = CacheScope::Private ]) : self
Only the methods the specification makes cacheable are worth naming; any other is accepted and simply never consulted.
Parameters
- $method : string
- $ttlMs : int
- $scope : CacheScope = CacheScope::Private
Return values
self__construct()
private
__construct(int $ttlMs, CacheScope $scope[, array<string, CacheScope}> $perMethod = [] ]) : mixed
Parameters
- $ttlMs : int
- $scope : CacheScope
- $perMethod : array<string, CacheScope}> = []