Securely store JSON
data and normal data
Used in PotatoDetection
Installation
npm install --save potato-cache
Setup
- Require the package
- Setup the cache path and secret key
- Set to true if mkdirp the directory doesnt exist. default
false
const PotatoCache = PotatoCache
API
write(key, data, callback)
Write data to cache asynchronously and callback a function with the given data written
throws
error
returns
data written
var obj = name: 'KitKat' owner: 'Nestle'PotatoCache
writeSync(key, data)
Write data synchronously and return the given data written
throws
error
returns
data written
var obj = name: 'KitKat' age: 21var cached = PotatoCacheconsole
read(key, callback)
Read data asynchronously and callback a function with the data
throws
error
returns
data from cache
PotatoCache
readSync(key, callback)
Read data synchronously and callback a function with the data
throws
error
returns
data from cache
var data = PotatoCacheconsole
exists(key)
Checks if a cache exists
returns
promise
PotatoCache
existsThenRead(key)
Checks if a cache exists, and if it does, it will return the data in the Promise resolve
returns
promise and data
PotatoCache
isNotExpired(key, maxAge)
Checks if a cache exists and is not expired
maxAge
checks if the cache is older than x minutes
- default value is 3 hours
returns
promise
PotatoCache
isNotExpiredThenRead(key, maxAge)
Checks if a cache exists and is not expired then reads the data and returns it
maxAge
checks if the cache is older than x minutes
- default value is 3 hours
returns
promise and data
PotatoCache
getPath(key)
throws
error
returns
the given path and hashed md5 filename for the cache
console
purge(key)
Deletes a cache asynchronously
throws error
PotatoCache
purgeSync(key)
Deletes a cache synchronously
throws error
PotatoCache
trash()
Clears the entire cache folder asynchronously
throws error
PotatoCache
trashSync()
Clears the entire cache folder synchronously
throws error
PotatoCache
getSize(callback)
returns
the size of the cache folder in megabytes asynchronously
throws error
PotatoCache