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

simple-object-to-json-cacher

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

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)

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
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);

Keywords

FAQs

Package last updated on 12 Sep 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc