1.3.1 • Published 4 years ago

keyv-lru-files v1.3.1

Weekly downloads
28
License
MIT
Repository
github
Last release
4 years ago

Keyv lru files

Build Status

A file cache inspired by lru-cache. Least recently used files are deleted. It's helpful if your filesystem uses atime. Everything is written to files and nothing is kept in-memory.

Install

npm install keyv-lru-files

Usgae

var lrufiles = require("keyv-lru-files");

var cache = new lrufiles({
	dir: "cache" 			// directory to store caches files
	files: 100,       // maximum number of files
	size: "1 GB",     // maximum total file size
	check: 10,  // interval of stale checks in minutes
});

// add a file to cache. you can submit a buffer...
await cache.set("filename.ext", new Buffer("data"));

// ... readable stream ...
await cache.set("otherfile.ext", fs.createReadableStream("/some/filename.ext"));

// ... or object
await cache.set("objectfile.json", {hello: "world"});

// get a file from cache
// the value is a Buffer
let value = cache.get("somefile.ext");

// get a readable stream to a cached file, straight...
let stream = await cache.stream("anyfile.ext");

// check if a file is cached
let exists = await cache.has("filename.ext");

// update a files access time
await cache.touch("file/changed.txt");

// get list of all files cached
let keys = await cache.keys();

// remove a file from cache
let deleted = await cache.delete("file/changed.txt");

// manually remove old files
await cache.cache_cleaner();

// empty everything
await cache.clear();

// All functions return a promise so following syntax can be used for all functions
// this is alternate way when you don't want to use async / await.
cache.has("filename.ext").then(function(exists){
	// do something...
}).catch(function(err){
	// there was error checking file existence
});
1.3.1

4 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.5.0

5 years ago