Class CachePolicy
publicA basic CachePolicy that can be added to the Store service.
Determines staleness based on time since the request was last received from the API
using the date
header.
Invalidates any request for which cacheOptions.types
was provided when a createRecord
request for that type is successful.
For this to work, the createRecord
request must include the cacheOptions.types
array
with the types that should be invalidated, or its request should specify the identifiers
of the records that are being created via records
. Providing both is valid.
[!NOTE] only requests that had specified
cacheOptions.types
and occurred prior to the createRecord request will be invalidated. This means that a given request should always specify the types that would invalidate it to opt into this behavior. Abstracting this behavior via builders is recommended to ensure consistency.
This allows the Store's CacheHandler to determine if a request is expired and should be refetched upon next request.
The Fetch
handler provided by @ember-data/request/fetch
will automatically
add the date
header to responses if it is not present.
[!NOTE] Date headers do not have millisecond precision, so expiration times should generally be larger than 1000ms.
Usage:
import { CachePolicy } from '@ember-data/request-utils';
import DataStore from '@ember-data/store';
// ...
export class Store extends DataStore {
constructor(args) {
super(args);
this.lifetimes = new CachePolicy({ apiCacheSoftExpires: 30_000, apiCacheHardExpires: 60_000 });
}
}
Methods
Properties
No documented items
Events
No documented items