tomanagle / in-memory-fetch-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

in-memory-fetch-cache

Build Status

Usage

/* 
* Define a fetch function
* Could be a network request, a database call or a call to the file system
*/
function fetchFunction(){
  return aFetchCall()
}

// Define your cache - TypeScript
 const cache = new Cache<User, { id: number }>({
      fetchFunction: fetchFunction,
      hashKey: 'id' // What should be used to get the data from the cache?
    })

// Define your cache - JavaScript
 const cache = new Cache({
      fetchFunction: fetchFunction,
      hashKey: 'id' // What should be used to get the data from the cache?
    })

// Fetch the data from the fetch function, or the cache
const data = await cache.getData({ id: 1 })

// Returns the contents of the cache
const dump = await cache.dump()

About

License:MIT License


Languages

Language:TypeScript 100.0%