![]() | Name | Last modified | Size | Description |
---|---|---|---|---|
![]() | Parent Directory | - | ||
![]() | README.html | 2023-08-18 08:02 | 14K | |
![]() | README.txt | 2023-08-18 08:02 | 2.5K | |
![]() | copyright | 2021-10-16 13:36 | 2.4K | |
![]() | changelog.Debian.gz | 2023-08-18 08:02 | 1.3K | |
A stupidly simple key/value storage using files to persist the data
npm i --save flat-cache
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
.setKey('key', { foo: 'var' });
cache
// get a key from the cache
.getKey('key') // { foo: 'var' }
cache
// fetch the entire persisted object
.all() // { 'key': { foo: 'var' } }
cache
// remove a key
.removeKey('key'); // removes a key from the cache
cache
// save it to disk
.save(); // very important, if you don't save no changes will be persisted.
cache// 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
.clearCacheById('cacheId') // removes the cacheId document if one exists.
flatCache
// delete all cache
.clearAll(); // remove the cache directory flatCache
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.
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.stringify-able
ones, meaning no circular referencesObject.observe
to deliver
the changes to disk, but I wanted to keep this module intentionally dumb
and simplecache.save()
is
called. If this is not desired, you can pass true
to the
save call like: cache.save( true /* noPrune */ )
.MIT