1.0.17 • Published 7 years ago

potato-cache v1.0.17

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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 = require('potato-cache')

PotatoCache.setup(path, secret, true)

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.write('chocolate', obj, (data) => {
  ...
})

writeSync(key, data)

Write data synchronously and return the given data written

throws error

returns data written

var obj = {name: 'KitKat', age: 21}
var cached = PotatoCache.write('chocolate', obj)
console.log(cached)

read(key, callback)

Read data asynchronously and callback a function with the data

throws error

returns data from cache

PotatoCache.read('chocolate', (data) => {
  ...
})

readSync(key, callback)

Read data synchronously and callback a function with the data

throws error

returns data from cache

var data = PotatoCache.readSync('chocolate')
console.log(data)

exists(key)

Checks if a cache exists

returns promise

PotatoCache.exists('chocolate')
  .then(() => {
    ...
  })
  .catch(() => {
    var obj = {name: 'KitKat', owner: 'Nestle'}
    PotatoCache.writeSync('chocolate', obj)
  })

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.existsThenRead('chocoloate')
  .then(data => {
      ...
  })
  .catch(() => {
      ...
  })

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.isNotExpired('chocolate')
  .then(() => {
    ...
  })
  .catch(res => {
    console.log(res) // 'File is x minutes too old'
    var obj = {name: 'KitKat', owner: 'Nestle'}
    PotatoCache.writeSync('chocolate', obj)
  })

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.isNotExpiredThenRead('chocolate')
  .then(data => {
    console.log(data)
  })
  .catch(res => {
    console.log(res) // 'File is x minutes too old'
    var obj = {name: 'KitKat', owner: 'Nestle'}
    PotatoCache.writeSync('chocolate', obj)
  })

getPath(key)

throws error

returns the given path and hashed md5 filename for the cache

console.log(PotatoCache.getPath('chocolate'))

purge(key)

Deletes a cache asynchronously

throws error

PotatoCache.purge('chocolate', () => {
  ...
})

purgeSync(key)

Deletes a cache synchronously

throws error

PotatoCache.purgeSync('chocolate')

trash()

Clears the entire cache folder asynchronously

throws error

PotatoCache.trash(() => {
  ...
})

trashSync()

Clears the entire cache folder synchronously

throws error

PotatoCache.trashSync()

getSize(callback)

returns the size of the cache folder in megabytes asynchronously

throws error

PotatoCache.getSize(size => {
  ...
})
1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

0.0.26

7 years ago

0.0.24

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago