Giter Site home page Giter Site logo

cacheify's Introduction

Cacheify

Cacheify is a caching layer for browserify transforms. You specify a transform and a cache and it handles the rest by wrapping everything in its own browserify transform that you'll pass to the bundling process.

You can also specify custom filter and hash functions to be specific about which files get cached, and how a file is decided to be unique.

Example usage

var cacheify = require('cacheify')
  , coffeeify = require('coffeeify')
  , level = require('level')
  , db = level('./cache');

...

var cachingCoffeeify = cacheify(coffeeify, db)

...

b.transform(cachingCoffeeify)

API

cacheify(transform, db)

Creates a new cacheify transform.

  • transform: The transform you want to cache the output of
  • db: A levelup-api compatible database object, or a function that returns such an object. This is where the results of cached transforms are stored.
cacheify.filter(fn)

Replaces the default filter function (always returns true) with a function of your choosing. The filter function is called per file and if it returns a truthy value we will cache the results of the transform of the file, or read from the cache if it's already there. If it returns false we will apply the original transform without caching.

  • fn: The filter function you want to use. It takes one argument, the file path. If fn is a RegExp object, cacheify.filter will wrap it in a function that tests each filename against it.
cacheify.hash(fn)

Replaces the default hash function (md5 of the file's contents) with a function of your choosing. The hash function will be used to generate a unique key for a file, that we will check to see if it exists in the DB before applying the original transform.

  • fn: The hash function you want to use. It takes two arguments, the file contents and the file path.

Changelog

  • 0.4.2 Updates concat-stream to remove a security vulneratbility. Thanks for @puzrin for the report (#11).

  • 0.4.0 Now passes transform options through to cachee streams.

  • 0.3.2 Now handles multiple errors in the cachee stream instead of only one.

  • 0.3.1 the second argument, db, can now be a function that returns a db. Useful if you need to close connections and unlock the leveldb between bundles.

  • 0.2.1: When the filter returns false, instead of passing an empty through pass the original uncached transform. That way it can handle what gets transformed and we only handle what gets cached.

  • 0.2.0: Do not use, has breaking bugs!! 0.2.1 fixes them. Apologies!

    • Changed the API significantly.
    • Added the ability to specify a filter function to be selective about which files are transformed.
    • Because hash is optional like filter, changed how you apply a custom hash function to be similar to how you apply a custom filter function.
    • Changed the order of arguments to cacheify, it takes the transform first and the db second
    • The db argument can now be a function instead of an object. If it is, it will call that function to get the db object. This gives you more flexibility when working in environments with complicated locking orders on the dbs.

License

BSD, see the LICENSE.md for more information.

cacheify's People

Contributors

hughsk avatar bockit avatar azu avatar

Stargazers

Raziel Anarki avatar Robert Cecil William'JR Hamilton  avatar Mehdi Lahlou avatar Anton avatar Sean Johnson avatar Denis Denisov avatar Miki Oracle avatar Maksim Ovcharik avatar doly mood avatar Csaba Tamás avatar Andrew Gatlabayan avatar 雨夜带刀 avatar Andrew Gerst avatar Exequiel Ceasar Navarrete avatar Jabar Marbu avatar Patrick Violette avatar Conor avatar OSdio avatar Christopher Van avatar Vasiliy Yorkin avatar Alex Kirszenberg avatar James Friend avatar Ryo Murayama avatar Yuya Saito avatar HIRAKI Satoru avatar  avatar Derek Reynolds avatar Yu Inao avatar Will Laurance avatar Andrey Sidorov avatar  avatar

Watchers

 avatar  avatar Nick Dima avatar James Cloos avatar

Forkers

hughsk azu

cacheify's Issues

Transform options

Some browserify transforms, like reactify for example, take an options object. Is it possible to pass the options object to cacheify?

Doesn't work with debowerify

Not sure if it's supposed to work with the debowerify transform but it breaks saying that it couldn't find the bower modules i'm requiring.

Cache Filter

I also noticed that cacheify caches all the required files for each transform it's wrapping. Could speed up the build process (possibly significantly) by adding a filter argument to only check files relevant to that transform, and return an unmodified through stream otherwise.

Gulp with plumber

I've been trying to use cacheify with gulp-browserify and gulp-plumber but there seems to be an issue.
Plumber is supposed to catch eventual errors and keep gulp running, in case of browserify the errors could be syntax errors in a source file. Without wrapping the transforms with cacheify plumber does it job fine but otherwise gulp gets interrupted when syntax errors occur. All I get from the terminal is:

stream.js:94
  throw er; // Unhandled stream error in pipe.

I also wrote about this here

grunt-browserify

Could you provide an example with grunt-browserify?

{
    transform: [
        [
            'babelify', { }
        ]
    ]
},

files: {}

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.