npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-memory-cache

v0.3.0

Published

A gulp plugin to cache files in memory

Downloads

710

Readme

npm version Build Status Coverage Status

gulp-memory-cache

A gulp plugin for caching files in memory with incremental build helpers.

It is aimed to be used with Gulp 4, see why: Building with Gulp 4: Incremental builds.

If you are using Gulp 3, you will need to use gulp-memory-cache in combination with gulp-cached or similar. However be aware that both modules will maintain their own cache and therefore files are cached twice.

Usage

var gulp   = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var cache  = require('gulp-memory-cache');

gulp.task('buildJs', function () {
    return gulp.src('src/**/*.js', {since: cache.lastMtime('js')})
        .pipe(jshint())
        .pipe(cache('js'))
        .pipe(concat('app.js'))
        .pipe(dest('build'));
});

gulp.task('watch', function () {
    gulp.watch('src/**/*.js', gulp.series('buildJs'))
        .on('change', cache.update('js'));
});

gulp.task('build', gulp.series('buildJs', 'watch'));

API

cache(name, save)

  • name (required): the cache name
  • save (optional, default to true): whether or not to save / update cache

If save is truthy, it will save (update) streamed files to cache with name name. cache() then returns a stream containing all files in cache in the order they were added.

cache.save(name)

  • name (required): the cache name

Saves streamed files to cache with name name. Useful if you want to save in a pipeline for retrieving later (in the same or another pipeline).

cache.flush(name)

  • name (required): the cache name

Flush (remove all files) cache name. Handy to force a stream to process again all its files.

cache.forget(name, filePath[, fn])

  • name (required): the cache name
  • filePath (required): the file path
  • fn: a file path transformation function

Remove from cache name file with path filePath. fn is a file path transformation function (see below for an example with cache.update().

cache.update(name[, fn])

  • name (required): the cache name
  • fn: a file path transformation function

To use in watch.on('change', ...) in order to avoid boilerplate code. It will automatically remove files which have been deleted from cache name. fn is a function to transform a file path and can be useful for removing a file from cache which name has been altered by a gulp plugin.

gulp.watch('src/**/*.tpl.html', gulp.series('bundlePartials'))
    .on('change', cache.update('partials', function (filePath) {
        return filePath.replace(/.html$/, '.js')
    }));

cache.lastMtime(name)

  • name (required): the cache name

Returns the most recent mtime (modified time) of all files in specified cache, can be used in lieu of gulp.lastRun().

cache.lastUpdated(name)

  • name (required): the cache name

Returns the last time a cache was updated, can also be used in lieu of gulp.lastRun().

cache.get(name)

  • name (optional): the cache name

Return cache named name, or all cached data if name is not supplied.

Cache API

cache.get(cacheName) returns a Cache object.