Giter Site home page Giter Site logo

memo-again's Introduction

Two-level memoizer with promises stores function values in memory and/or file caches. Writes to memory and file caches can be independently changed on demand. The file cache is stored in the application local folder by default, so you may want to add local/ to .gitignore.

Memoizer

For more examples, see test/memoizer.js

const { Memoizer } = require("memo-again");
var f = x=>42+x;
var mzr = new Memoizer();
var fmemo = mzr.memoize(f);

fmemo(0); // 42 
fmemo(0); // 42 (cached)
fmemo(1); // 43
fmemo(1); // 43 (cached)

Files

File iterators and more...

Iterate over all files in directory (async)

Async generator permits precise control of thread usage.

    var files = [];
    for await (let f of Files.files(FILES_DIR)) {
        files.unshift(f);
    }
    // [ "hello", "sub/basement", "universe", ]
Customize file iteration

Async generator provides fs.Stats

    var opts = {
        root: FILES_DIR,
        stats: true, // return fs.Stats object
        absolute: true, // return absolute filepath
    }
    for await (let f of Files.files(FILES_DIR)) {
        console.log(JSON.stringify(f));
        // {path:..., stats:...}
    }
Spread-syntax initialization (sync-only)

Sync generator uses fs sync methods and can be slower.

    var files = [...Files.filesSync(FILES_DIR)];
    // [ "hello", "sub/basement", "universe", ]
Application folder

The application that uses this library

console.log(Files.APP_DIR);
// /home/somebody/myapp
Local folder

Use "local" folder for application data. Remember to add it to .gitignore

console.log(Files.LOCAL_DIR);
// /home/somebody/myapp/local

memo-again's People

Contributors

firepick1 avatar

Watchers

James Cloos avatar  avatar  avatar Noé Ismet avatar

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.