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() |
| Modifier and Type | Method and Description |
|---|---|
NormalizedCache |
chain(NormalizedCache cache) |
abstract void |
clearAll()
Clears all records from the cache.
|
java.util.Map<java.lang.Class,java.util.Map<java.lang.String,Record>> |
dump() |
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). |
java.util.Set<java.lang.String> |
merge(Record record,
CacheHeaders cacheHeaders) |
com.apollographql.apollo.api.internal.Optional<NormalizedCache> |
nextCache() |
protected abstract java.util.Set<java.lang.String> |
performMerge(Record apolloRecord,
CacheHeaders cacheHeaders) |
static java.lang.String |
prettifyDump(java.util.Map<java.lang.Class,java.util.Map<java.lang.String,Record>> dump) |
boolean |
remove(CacheKey cacheKey)
Remove cached record by the key
|
abstract boolean |
remove(CacheKey cacheKey,
boolean cascade)
Remove cached record by the key
|
@Nullable public abstract Record loadRecord(@NotNull java.lang.String key, @NotNull 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.@NotNull public java.util.Collection<Record> loadRecords(@NotNull java.util.Collection<java.lang.String> keys, @NotNull 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.@NotNull
public java.util.Set<java.lang.String> merge(@NotNull
Record record,
@NotNull
CacheHeaders cacheHeaders)
record - The Record to merge.cacheHeaders - The CacheHeaders associated with the request which generated this record.Record.mergeWith(Record).@NotNull
public java.util.Set<java.lang.String> merge(@NotNull
java.util.Collection<Record> recordSet,
@NotNull
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).@NotNull
protected abstract java.util.Set<java.lang.String> performMerge(@NotNull
Record apolloRecord,
@NotNull
CacheHeaders cacheHeaders)
public abstract void clearAll()
ApolloClient.clearNormalizedCache() for a thread-safe access to this method.public boolean remove(@NotNull
CacheKey cacheKey)
cacheKey - of record to be removedtrue if record with such key was successfully removed, false otherwisepublic abstract boolean remove(@NotNull
CacheKey cacheKey,
boolean cascade)
cacheKey - of record to be removedcascade - defines if remove operation is propagated to the referenced entitiestrue if record with such key was successfully removed, false otherwisepublic final NormalizedCache chain(@NotNull NormalizedCache cache)
public final com.apollographql.apollo.api.internal.Optional<NormalizedCache> nextCache()
public java.util.Map<java.lang.Class,java.util.Map<java.lang.String,Record>> dump()
public static java.lang.String prettifyDump(java.util.Map<java.lang.Class,java.util.Map<java.lang.String,Record>> dump)