Skip to content

Install

Ovidiu Bokar edited this page Apr 16, 2021 · 1 revision
  npm i -S node-file-caching 

This package has 4 main methods that can be used and assumes that the defualt cache folder is .cache with a default TTL of 60 minutes.

set()

This method has 2 mandatory and 2 optional parameters and you'll need to use it for setting the cache. The output of this method will be true.

key = Your own cache identifier

value = Value that you would like to store

ttl = This is optional. Is set to 60 minutes by default.

location = This is optional. Is set to default location of .cache, however, please don't use it as currently there's no state of configuration for persisting the cache location.

const {set} = require('node-file-caching');

set("myCacheKey",{foo:"bar"});

get()

This method has 1 mandatory parameter, called key, which is used to get the cache file. This method has 2 response states:

  1. false = when the key doesn't exist of cache key doesn't have any content

  2. string = it will return the file contents of the key

key = Cache key identifier

const {get} = require('node-file-caching');

const cacheData = get("myCacheKey");

remove()

This method has 1 mandatory parameter, called key, which is used to identify the cache file and remove it. This method has 2 response states:

  1. false = when the key doesn't exist

  2. true = when the key has been removed

key = Cache key identifier

const {remove} = require('node-file-caching');

remove("myCacheKey");

removeAll()

This method will clear the .cache folder of any files and it will return true as response.

Clone this wiki locally