dataloader-cache-lru
LRU (least recently used) cache for Facebook's DataLoader.
Installation
npm install dataloader-cache-lru --save
Documentation
DataLoader, by default, uses the standard Map which simply grows until the DataLoader is released. The default is appropriate when requests to your application are short-lived.
Longer lived DataLoaders, such as ones which persist between GraphQL queries, will build up memory pressure unless the size of the cache is controlled. Furthermore, if records mutate, their cache entries must be removed.
This DataLoader-compatible cache implements a LRU (least recently used) cache, it deletes the least recently used items when the cache size is exceeded.
Complete Example
const DataLoader = ;const dataLoaderCacheLru = ; const cacheMap = ; // see options in isaacs/node-lru-cacheconst dataloader = batchLoadFn cacheMap ; Promiseall 'a' 'b' 'c' 'd' 'e' ; // record with key 'd' has been mutateddataloaderclear'd';console; // ['c', 'e'] { return Promiseall keys ;}
License
Copyright (c) 2017
Licensed under the MIT license.