Git Product home page Git Product logo

fs-lazy-cache's Introduction

fs-lazy-cache

Another file system cache for Node.

Lazy-loads files into a memory cache. Caches files on write. There's an option to not write file saves to disk and only keep in the cache. A version of scanDir is included.

Installation

npm install fs-lazy-cache --save

or

yarn add fs-lazy-cache

Usage

Check out the source/test.js file for some example usage.

readFile

Load a file from the filesystem and add a copy to the cache.

Uses fs.readFile() internally.

let fs = require('fs-lazy-cache');

fs.readFile('somefile.txt', function (err, output) {
    if (err) throw err;
    
    return output;
})

readFileSync

Load a file from the filesystem and add a copy to the cache.

Uses fs.readFileSync() internally.

let fs = require('fs-lazy-cache');

let output = fs.readFile('somefile.txt');

outputFile

Save a file to the filesystem and store a copy in the cache.

Uses 'fs-extra.outputFile` internally.

fs.outputFile('somefile.txt', 'some contents', true, 5000, function (err) {
    if (err) throw err;
});    

file The filename.

contents The file string contents.

toDisk If the file should be saved to disk or only to the cache.

timeout (Optional) Timeout in milliseconds before deleting from the cache.

callback Same callback functionality as fs-extra.outputFile or fs.writeFile

outputFileSync

Same as above but with no callback.

Uses 'fs-extra.outputFileSync` internally.

fs.outputFileSync('somefile.txt', 'some contents', false, 2000); 

scanDir

Scan the cache for files in a directory. Note this DOES NOT scan the filesystem.

let filesArray = scanDir(__dirname);

Credits

https://github.com/rjjakes

License

MIT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.