Merge pull request #31841 from artola/master

Add QueryResponseCache to relay-runtime
This commit is contained in:
Eloy Durán
2019-01-02 19:20:23 +01:00
committed by GitHub
2 changed files with 22 additions and 0 deletions
+18
View File
@@ -138,6 +138,24 @@ export type SubscribeFunction = (
observer: LegacyObserver<QueryPayload>
) => RelayObservable<QueryPayload> | Disposable;
// ~~~~~~~~~~~~~~~~~~~~~
// RelayQueryResponseCache
// Version: Relay 1.3.0
// File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayQueryResponseCache.js
// ~~~~~~~~~~~~~~~~~~~~~
/**
* A cache for storing query responses, featuring:
* - `get` with TTL
* - cache size limiting, with least-recently *updated* entries purged first
*/
export class QueryResponseCache {
constructor(options: {size: number; ttl: number});
clear(): void;
get(queryID: string, variables: Variables): QueryPayload | null;
set(queryID: string, variables: Variables, payload: QueryPayload): void;
}
// ~~~~~~~~~~~~~~~~~~~~~
// RelayStoreTypes
// Version: Relay 1.3.0
@@ -7,6 +7,7 @@ import {
ViewerHandler,
RecordSourceInspector,
commitLocalUpdate,
QueryResponseCache,
ROOT_ID,
} from "relay-runtime";
@@ -33,6 +34,9 @@ function fetchQuery(operation: any, variables: { [key: string]: string }, cacheC
// Create a network layer from the fetch function
const network = Network.create(fetchQuery);
// Create a cache for storing query responses
const cache = new QueryResponseCache({size: 250, ttl: 60000});
// ~~~~~~~~~~~~~~~~~~~~~
// Environment
// ~~~~~~~~~~~~~~~~~~~~~