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

cache2file

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache2file

Cache string information to files

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

#Cache to File module for Node.js

It stores cache data in files that can expire. Stored data can be in any format Buffer supports (utf8 [default], ascii, binary).

#Install

npm install cache2file

#Usage

var Cache2File = require('cache2file'),
    // Path to store the cache files
    cachePath = './cache',
    // Timeout in milliseconds
    timeout = 60000,
    // Generate a new cache
    cache = new Cache2File(cachePath, timeout);

cache.set('cacheKey', doIntensiveStuff());

// ... some time later
cache.get('cacheKey', function (err, data) {
  if (!err) {
    // We have the data, do whatever we want.
  }
  else {
    // Cache timed out, or removed, so store it again.
    data = doIntensiveStuff();
    cache.set('cacheKey', data);
  }

  processData(data);
});

// Remove cached data.
cache.remove('cacheKey');

Cache2File uses it's own function Cache2File.generateKey to generate a hash for the filename to store data in. It can be replaced with your own filename generating algorithm if you wish. Hashing was generally required to only have ascii characters in filenames and no / characters, as there is no restriction for the characters in the key.

key's string value should be less then 200 characters so the filesystem can handle the filename.

To remove multiple cache files, use cache.removeAll(callback, keyCached, expired)

Where if keyCached is set to true, remove those whose key was touched in the lifetime of the cache object. If it is false (default) all cache files in the cache directory will be removed (those that has the extension .cache).
If expired is set to true (default is false) it will only remove expired cache files.
These filters can be combined.

TODO

Handle cache read / write concurrency.

Keywords

FAQs

Package last updated on 03 Feb 2011

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