Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

simple-object-to-json-cacher

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-object-to-json-cacher

Saves JS Object synchronously to plain text JSON file, and loads. (Basic Simple Unencrypted Serialisation)


Version published
Weekly downloads
23
decreased by-77.67%
Maintainers
1
Weekly downloads
 
Created
About

Saves JS Object synchronously to plain text JSON file, and loads. (Basic Simple Unencrypted Serialisation)

Usage

Declare a path to the folder where the cache will be stored. If the folder exists it will be used, if the last folder in the path does not exist it will be created.

let CACHEFOLDERPATH = "./example/folderForCachedObjects";

Create a Cacher object:

let cacher = Cacher(CACHEFOLDERPATH);

To save an object, call the save function of the Cacher object and provide the name of the file to save to without the JSON extension and the object as the second argument. The file will be saved in the Cache directory given as in the example above as CACHEFOLDERPATH. If the file already exists it will be replaced with the contents of the object.

cacher.save("cachedObject", exampleObjectToSave);

To restore and load an object, call the load function on the Cacher object and provide the name of the file to restore the object from without the JSON extension.

let loadedCachedObject = cacher.load("cachedObject");
console.log(loadedCachedObject);

FAQs

Package last updated on 09 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts