Class <Interface> Cache
publicThe interface for EmberData Caches.
A Cache handles in-memory storage of Document and Resource data.
changedAttrs (identifier) Record<string, [unknown, unknown]> public
Defined in ../packages/core-types/src/cache.ts:357
- identifier
- returns
- Record<string, [unknown, unknown]>
{
: [ , ] }
Query the cache for the changed attributes of a resource.
Returns a map of field names to tuples of [old, new] values
{ <field>: [<old>, <new>] }
changedRelationships (identifier) Map<string, RelationshipDiff> public
Defined in ../packages/core-types/src/cache.ts:395
- identifier
- StableRecordIdentifier
- returns
- Map<string, RelationshipDiff>
Query the cache for the changes to relationships of a resource.
Returns a map of relationship names to RelationshipDiff objects.
type RelationshipDiff =
| {
kind: 'collection';
remoteState: StableRecordIdentifier[];
additions: Set<StableRecordIdentifier>;
removals: Set<StableRecordIdentifier>;
localState: StableRecordIdentifier[];
reordered: boolean;
}
| {
kind: 'resource';
remoteState: StableRecordIdentifier | null;
localState: StableRecordIdentifier | null;
};
clientDidCreate (identifier, createArgs) public
Defined in ../packages/core-types/src/cache.ts:272
- identifier
- createArgs
[LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
It returns properties from options that should be set on the record during the create process. This return value behavior is deprecated.
commitWasRejected (identifier, errors) public
Defined in ../packages/core-types/src/cache.ts:307
- identifier
- errors
[LIFECYCLE] Signals to the cache that a resource was update via a save transaction failed.
didCommit (identifier, data) SingleResourceDataDocument public
Defined in ../packages/core-types/src/cache.ts:295
- identifier
- the primary identifier that was operated on
- data
- a document in the cache format containing any updated data
- returns
- SingleResourceDataDocument
[LIFECYCLE] Signals to the cache that a resource was successfully updated as part of a save transaction.
diff public
Defined in ../packages/core-types/src/cache.ts:201
Generate the list of changes applied to all record in the store.
Each individual resource or document that has
been mutated should be described as an individual
Change
entry in the returned array.
A Change
is described by an object containing up to
three properties: (1) the identifier
of the entity that
changed; (2) the op
code of that change being one of
upsert
or remove
, and if the op is upsert
a patch
containing the data to merge into the cache for the given
entity.
This patch
is opaque to the Store but should be understood
by the Cache and may expect to be utilized by an Adapter
when generating data during a save
operation.
It is generally recommended that the patch
contain only
the updated state, ignoring fields that are unchanged
interface Change {
identifier: StableRecordIdentifier | StableDocumentIdentifier;
op: 'upsert' | 'remove';
patch?: unknown;
}
dump Promise<ReadableStream> public
Defined in ../packages/core-types/src/cache.ts:239
- returns
- Promise<ReadableStream>
Serialize the entire contents of the Cache into a Stream
which may be fed back into a new instance of the same Cache
via cache.hydrate
.
fork public
Defined in ../packages/core-types/src/cache.ts:174
- returns
Promise
Create a fork of the cache from the current state.
Applications should typically not call this method themselves, preferring instead to fork at the Store level, which will utilize this method to fork the cache.
getAttr (identifier, field) Unknown public
Defined in ../packages/core-types/src/cache.ts:333
- identifier
- field
- returns
- Unknown
Retrieve the data for an attribute from the cache
getErrors (identifier) JsonApiError[] public
Defined in ../packages/core-types/src/cache.ts:479
- identifier
- returns
- JsonApiError[]
Query the cache for any validation errors applicable to the given resource.
getRelationship (identifier, field) public
Defined in ../packages/core-types/src/cache.ts:448
- identifier
- StableRecordIdentifier
- field
- String
- returns
resource relationship object
Query the cache for the current state of a relationship property
hasChangedAttrs (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:373
- identifier
- returns
- Boolean
Query the cache for whether any mutated attributes exist
hasChangedRelationships (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:424
- identifier
- StableRecordIdentifier
- returns
- Boolean
Query the cache for whether any mutated attributes exist
hydrate (stream) Promise<void> public
Defined in ../packages/core-types/src/cache.ts:250
- stream
- ReadableStream
- returns
- Promise<void>
hydrate a Cache from a Stream with content previously serialized from another instance of the same Cache, resolving when hydration is complete.
This method should expect to be called both in the context of restoring the Cache during application rehydration after SSR AND at unknown times during the lifetime of an already booted application when it is desired to bulk-load additional information into the cache. This latter behavior supports optimizing pre/fetching of data for route transitions via data-only SSR modes.
isDeleted (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:510
- identifier
- returns
- Boolean
Query the cache for whether a given resource is marked as deleted (but not necessarily persisted yet).
isDeletionCommitted (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:521
- identifier
- returns
- Boolean
Query the cache for whether a given resource has been deleted and that deletion has also been persisted.
isEmpty (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:489
- identifier
- returns
- Boolean
Query the cache for whether a given resource has any available data
isNew (identifier) Boolean public
Defined in ../packages/core-types/src/cache.ts:499
- identifier
- returns
- Boolean
Query the cache for whether a given resource was created locally and not yet persisted.
merge (cache) public
Defined in ../packages/core-types/src/cache.ts:187
- cache
- Cache
- returns
Promise
Merge a fork back into a parent Cache.
Applications should typically not call this method themselves, preferring instead to merge at the Store level, which will utilize this method to merge the caches.
mutate (mutation) Void public
Defined in ../packages/core-types/src/cache.ts:99
- mutation
- Mutation
- returns
- Void
Update the "local" or "current" (unpersisted) state of the Cache
patch (op) Void public
Defined in ../packages/core-types/src/cache.ts:85
- op
- Operation
the operation to perform
- returns
- Void
Update the "remote" or "canonical" (persisted) state of the Cache by merging new information into the existing state.
Note: currently the only valid resource operation is a MergeOperation which occurs when a collision of identifiers is detected.
peek (identifier) ResourceDocument | ResourceBlob | null public
Defined in ../packages/core-types/src/cache.ts:109
- identifier
- StableRecordIdentifier | StableDocumentIdentifier
- returns
- ResourceDocument | ResourceBlob | null
the known resource data
Peek resource data from the Cache.
In development, if the return value is JSON the return value will be deep-cloned and deep-frozen to prevent mutation thereby enforcing cache Immutability.
This form of peek is useful for implementations that want to feed raw-data from cache to the UI or which want to interact with a blob of data directly from the presentation cache.
An implementation might want to do this because de-referencing records which read from their own blob is generally safer because the record does not require retainining connections to the Store and Cache to present data on a per-field basis.
This generally takes the place of getAttr
as
an API and may even take the place of getRelationship
depending on implementation specifics, though this
latter usage is less recommended due to the advantages
of the Graph handling necessary entanglements and
notifications for relational data.
peekRequest (UNKNOWN) StructuredDocument<ResourceDocument> | null public
Defined in ../packages/core-types/src/cache.ts:144
- UNKNOWN
- StableDocumentIdentifier
- returns
- StructuredDocument<ResourceDocument> | null
Peek the Cache for the existing request data associated with a cacheable request
This is effectively the reverse of put
for a request in
that it will return the the request, response, and content
whereas peek
will return just the content
.
put (doc) ResourceDocument public
Defined in ../packages/core-types/src/cache.ts:61
- doc
- StructuredDocument
- returns
- ResourceDocument
Cache the response to a request
Unlike store.push
which has UPSERT
semantics, put
has replace
semantics similar to
the http
method PUT
the individually cacheable resource data it may contain should upsert, but the document data surrounding it should fully replace any existing information
Note that in order to support inserting arbitrary data
to the cache that did not originate from a request put
should expect to sometimes encounter a document with only
a content
member and therefor must not assume the existence
of request
and response
on the document.
rollbackAttrs (identifier) String[] public
Defined in ../packages/core-types/src/cache.ts:383
- identifier
- returns
- String[]
the names of fields that were restored
Tell the cache to discard any uncommitted mutations to attributes
This method is a candidate to become a mutation
rollbackRelationships (identifier) String[] public
Defined in ../packages/core-types/src/cache.ts:434
- identifier
- StableRecordIdentifier
- returns
- String[]
the names of relationships that were restored
Tell the cache to discard any uncommitted mutations to relationships.
This will also discard the change on any appropriate inverses.
This method is a candidate to become a mutation
setAttr (identifier, field, value) public
Defined in ../packages/core-types/src/cache.ts:344
- identifier
- field
- value
Mutate the data for an attribute in the cache
This method is a candidate to become a mutation
setIsDeleted (identifier, isDeleted) public
Defined in ../packages/core-types/src/cache.ts:466
- identifier
- isDeleted
- Boolean
Update the cache state for the given resource to be marked as locally deleted, or remove such a mark.
This method is a candidate to become a mutation
unloadRecord (identifier) public
Defined in ../packages/core-types/src/cache.ts:318
- identifier
[LIFECYCLE] Signals to the cache that all data for a resource should be cleared.
This method is a candidate to become a mutation
upsert (identifier, data, hasRecord) Void | string[] public
Defined in ../packages/core-types/src/cache.ts:159
- identifier
- data
- hasRecord
- returns
- Void | string[]
if
hasRecord
is true then calculated key changes should be returned
Push resource data from a remote source into the cache for this identifier
willCommit (identifier) public
Defined in ../packages/core-types/src/cache.ts:285
- identifier
[LIFECYCLE] Signals to the cache that a resource will be part of a save transaction.