Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

flat-cache

Package Overview
Dependencies
2
Maintainers
1
Versions
23
Issues
File Explorer

Advanced tools

flat-cache

A stupidly simple key/value storage using files to persist some data

    3.0.4latest

Version published
Maintainers
1
Weekly downloads
23,238,042
increased by0.82%

Weekly downloads

Changelog

Source

v3.0.4

  • Refactoring
    • add files by name to the list of exported files - 89a2698, [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:35:39

Readme

Source

flat-cache

A stupidly simple key/value storage using files to persist the data

NPM Version Build Status

install

npm i --save flat-cache

Usage

var flatCache = require('flat-cache') // loads the cache, if one does not exists for the given // Id a new one will be prepared to be created var cache = flatCache.load('cacheId'); // sets a key on the cache cache.setKey('key', { foo: 'var' }); // get a key from the cache cache.getKey('key') // { foo: 'var' } // fetch the entire persisted object cache.all() // { 'key': { foo: 'var' } } // remove a key cache.removeKey('key'); // removes a key from the cache // save it to disk cache.save(); // very important, if you don't save no changes will be persisted. // cache.save( true /* noPrune */) // can be used to prevent the removal of non visited keys // loads the cache from a given directory, if one does // not exists for the given Id a new one will be prepared to be created var cache = flatCache.load('cacheId', path.resolve('./path/to/folder')); // The following methods are useful to clear the cache // delete a given cache flatCache.clearCacheById('cacheId') // removes the cacheId document if one exists. // delete all cache flatCache.clearAll(); // remove the cache directory

Motivation for this module

I needed a super simple and dumb in-memory cache with optional disk persistance in order to make a script that will beutify files with esformatter only execute on the files that were changed since the last run. To make that possible we need to store the fileSize and modificationTime of the files. So a simple key/value storage was needed and Bam! this module was born.

Important notes

  • If no directory is especified when the load method is called, a folder named .cache will be created inside the module directory when cache.save is called. If you're committing your node_modules to any vcs, you might want to ignore the default .cache folder, or specify a custom directory.
  • The values set on the keys of the cache should be stringify-able ones, meaning no circular references
  • All the changes to the cache state are done to memory
  • I could have used a timer or Object.observe to deliver the changes to disk, but I wanted to keep this module intentionally dumb and simple
  • Non visited keys are removed when cache.save() is called. If this is not desired, you can pass true to the save call like: cache.save( true /* noPrune */ ).

License

MIT

Changelog

changelog

Keywords

FAQs

What is flat-cache?

A stupidly simple key/value storage using files to persist some data

Is flat-cache popular?

The npm package flat-cache receives a total of 18,870,697 weekly downloads. As such, flat-cache popularity was classified as popular.

Is flat-cache well maintained?

We found that flat-cache demonstrated a not healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 08 Nov 2020
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc