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.
|
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) |
abstract boolean |
remove(CacheKey cacheKey)
Remove cached record by the key
|
@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 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).@Nonnull
protected abstract java.util.Set<java.lang.String> performMerge(@Nonnull
Record apolloRecord,
@Nonnull
CacheHeaders cacheHeaders)
public abstract void clearAll()
ApolloClient.clearNormalizedCache() for a thread-safe access to this method.public abstract boolean remove(@Nonnull
CacheKey cacheKey)
cacheKey - of record to be removedtrue if record with such key was successfully removed, false otherwisepublic final NormalizedCache chain(@Nonnull NormalizedCache cache)
public final com.apollographql.apollo.api.internal.Optional<NormalizedCache> nextCache()