jgable/cache-swap


A lightweight file swap cache backed by temp files

https://github.com/jgable/cache-swap

License: MIT

Language: JavaScript


cache-swap

NPM version Build status Dependency Status devDependency Status

A lightweight file swap cache backed by temp files.

Example

var swap = new CacheSwap({
    cacheDirName: "HoganizeSwap"
  }),
  processTemplate = function(template, done) {
    var templateStr = template.content,
      templatePath = template.path,
      templateHash = files.shaIt(templateStr);

    swap.getCached("hoganize", templateHash, function(err, cached) {
      if(err) {
        return done(err);
      }

      var yeahbrotha,
        stringed;

      if(cached) {
        yeahbrotha = cached.contents;
        try {
          addToHoganized(yeahbrotha, templatePath);
        } catch(e){
          return done(e);
        }

        done();
      } else {
        yeahbrotha = self._compileTemplate(templateStr, templatePath);
        // Add the compiled template to the cache swap for next time.
        swap.addCached("hoganize", templateHash, yeahbrotha, function(err) {
          if(err) {
            return done(err);
          }

          try {
            addToHoganized(yeahbrotha, templatePath);
          } catch(e) {
            return done(e);
          }

          done();
        });
      }

    });
  };

License

Licensed under the MIT License, Copyright 2013-2015 Jacob Gable

Project Statistics

Sourcerank 8
Repository Size 34.2 KB
Stars 2
Forks 3
Watchers 4
Open issues 2
Dependencies 9
Contributors 3
Tags 5
Created
Last updated
Last pushed

Top Contributors See all

Shinnosuke Watanabe Jacob Gable Yann Odeyer

Packages Referencing this Repo

cache-swap
A simple temp file based swap for speeding up operations
Latest release 0.3.0 - Updated - 2 stars

Recent Tags See all

v0.2.3 September 11, 2015
v0.2.2 August 10, 2015
v0.2.1 June 09, 2015
v0.2.0 February 21, 2015
0.0.6 February 19, 2014

Something wrong with this page? Make a suggestion

Last synced: 2017-02-08 13:28:44 UTC

Login to resync this repository