Cache remote resources in a key-value store
npm install cache-entity
import CacheEntity from 'cache-entity'
// Init
const cache = new CacheEntity({
users: 'https://jsonplaceholder.typicode.com/users/{key}',
todos: 'https://jsonplaceholder.typicode.com/todos/{key}',
})
// Add data
cache.add('todos', { 1: { name: 'Buy apples' }, 2: { name: 'Fix bugs' } })
// Lookup
const todo1 = await cache.lookup('todos', 1) // will not fetch
const todo2 = await cache.lookup('todos', 3) // will fetch
const todo3 = await cache.lookup('todos', 3) // will not fetch