public abstract class NormalizedCache
extends java.lang.Object
Record for reading requests from cache.
To serialize a Record to a standardized form use recordAdapter() which handles
call custom scalar types registered on the ApolloClient.
If a NormalizedCache cannot return all the records needed to read a response, it will
be considered a cache miss.
A NormalizedCache is recommended to implement support for CacheHeaders specified in
ApolloCacheHeaders.
A NormalizedCache can choose to store records in any manner.
See LruNormalizedCache for a in memory cache.| Constructor and Description |
|---|
NormalizedCache(RecordFieldAdapter recordFieldAdapter) |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
clearAll()
Clears all records from the cache.
|
abstract Record |
loadRecord(java.lang.String key,
CacheHeaders cacheHeaders) |
java.util.Collection<Record> |
loadRecords(java.util.Collection<java.lang.String> keys,
CacheHeaders cacheHeaders)
Calls through to
loadRecord(String, CacheHeaders). |
java.util.Set<java.lang.String> |
merge(java.util.Collection<Record> recordSet,
CacheHeaders cacheHeaders)
Calls through to
merge(Record, CacheHeaders). |
abstract java.util.Set<java.lang.String> |
merge(Record record,
CacheHeaders cacheHeaders) |
protected RecordFieldAdapter |
recordAdapter() |
public NormalizedCache(RecordFieldAdapter recordFieldAdapter)
recordFieldAdapter - An adapter which can deserialize and deserialize Recordprotected RecordFieldAdapter recordAdapter()
@Nullable public abstract Record loadRecord(@Nonnull java.lang.String key, @Nonnull CacheHeaders cacheHeaders)
key - The key of the record to read.cacheHeaders - The cache headers associated with the request which generated this record.Record for key. If not present return null.@Nonnull public java.util.Collection<Record> loadRecords(@Nonnull java.util.Collection<java.lang.String> keys, @Nonnull CacheHeaders cacheHeaders)
loadRecord(String, CacheHeaders).
Implementations should override this method if the underlying storage technology can offer an optimized manner
to read multiple records.keys - The set of Record keys to read.cacheHeaders - The cache headers associated with the request which generated this record.@Nonnull
public abstract java.util.Set<java.lang.String> merge(@Nonnull
Record record,
@Nonnull
CacheHeaders cacheHeaders)
record - The Record to merge.cacheHeaders - The CacheHeaders associated with the request which generated this record.Record.mergeWith(Record).@Nonnull
public java.util.Set<java.lang.String> merge(@Nonnull
java.util.Collection<Record> recordSet,
@Nonnull
CacheHeaders cacheHeaders)
merge(Record, CacheHeaders). Implementations should override this
method if the
underlying storage technology can offer an optimized manner to store multiple records.recordSet - The set of Records to merge.cacheHeaders - The CacheHeaders associated with the request which generated this record.Record.mergeWith(Record).public abstract void clearAll()
ApolloClient.clearNormalizedCache() for a thread-safe access to
this method.