mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Add QueryResponseCache
This commit is contained in:
Vendored
+18
@@ -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
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user