fs-simple-cache
v1.2.0
Published
Simple filesystem cache for node.
Downloads
24
Readme
fs-simple-cache
Simple filesystem cache for node.
Usage
npm install fs-simple-cache --save-dev
const path = require('path')
const Cache = require('fs-simple-cache')
const cache = new Cache({
cacheDirectory: path.resolve('.cache') // => optional, when not provided will use a temporary folder
})
let key = 'some content'
let content
// using json and gzip
if (!content = cache.get(key).content) {
content = 'do some intensive stuff to create the content'
cache.put(key, { content })
}
// using raw data and without gzip
const gzip = false
if (!content = cache.get(key, gzip)) {
content = 'do some intensive stuff to create the content'
cache.put(key, content, gzip)
}
// do something with the content
// delete the content
cache.delete(key, gzip)
// delete cache directory
cache.delete()