Documentation / @ember-data/store / index / CachePolicy
Defined in: packages/store/src/-private/cache-handler/types.ts:20
A service which an application may provide to the store via the store's lifetimes
property to configure the behavior of the CacheHandler.
The default behavior for request lifetimes is to never expire unless manually refreshed via cacheOptions.reload
or cacheOptions.backgroundReload
.
Implementing this service allows you to programatically define when a request should be considered expired.
(Interface) CachePolicy
Methods
didRequest()?
optional didRequest(
request,
response,
identifier,
store): void;
Defined in: packages/store/src/-private/cache-handler/types.ts:101
Invoked when a request has been fulfilled from the configured request handlers. This is invoked for both foreground and background requests once the cache has been updated.
Note, this is invoked regardless of whether the request has a cache-key.
It is best practice to notify the store of any requests marked as invalidated so that request subscriptions can reload when needed.
store.notifications.notify(identifier, 'invalidated');
This allows anything subscribed to the request to be notified of the change
e.g.
store.notifications.subscribe(identifier, (_, type) => {
if (type === 'invalidated') {
// do update
}
});
Parameters
request
response
null
| Response
| ResponseInfo
identifier
null
| StableDocumentIdentifier
store
Returns
void
isHardExpired()
isHardExpired(identifier, store): boolean;
Defined in: packages/store/src/-private/cache-handler/types.ts:36
Invoked to determine if the request may be fulfilled from cache if possible.
Note, this is only invoked if the request has a cache-key.
If no cache entry is found or the entry is hard expired, the request will be fulfilled from the configured request handlers and the cache will be updated before returning the response.
Parameters
identifier
store
Returns
boolean
true if the request is considered hard expired
isSoftExpired()
isSoftExpired(identifier, store): boolean;
Defined in: packages/store/src/-private/cache-handler/types.ts:51
Invoked if isHardExpired
is false to determine if the request should be update behind the scenes if cache data is already available.
Note, this is only invoked if the request has a cache-key.
If true, the request will be fulfilled from cache while a backgrounded request is made to update the cache via the configured request handlers.
Parameters
identifier
store
Returns
boolean
true if the request is considered soft expired
willRequest()?
optional willRequest(
request,
identifier,
store): void;
Defined in: packages/store/src/-private/cache-handler/types.ts:65
Invoked when a request will be sent to the configured request handlers. This is invoked for both foreground and background requests.
Note, this is invoked regardless of whether the request has a cache-key.
Parameters
request
identifier
null
| StableDocumentIdentifier
store
Returns
void