gulp-cache
A temp file based caching proxy task for gulp.
Install
npm i -D gulp-cache# or yarn add -D gulp-cache
Usage
;;;; gulp; gulp;
Complex usage example
;;;; const jsHintVersion = '2.4.1';const jshintOptions = fs; { // Key off the file contents, jshint version and options return ``;} gulp;
API
cache(pluginToCache [, options])
pluginToCache
Target plugin, the output of which will be cached.
options
Options for gulp-cache
plugin.
options.fileCache
[Optional] Where to store the cache objects
-
Defaults to
new Cache({ cacheDirName: 'gulp-cache' })
-
Create your own with
new cache.Cache({ cacheDirName: 'custom-cache' })
options.name
[Optional] The name of the bucket which stores the cached objects
- Defaults to
default
options.key
[Optional] What to use to determine the uniqueness of an input file for this task.
-
Can return a string or a
Promise
that resolves to a string. -
The result of this method is converted to a unique MD5 hash automatically; no need to do this yourself.
-
Defaults to
file.contents
if a Buffer, orundefined
if a Stream.
options.success
[Optional] How to determine if the resulting file was successful.
-
Must return a truthy value that is used to determine whether to cache the result of the task.
Promise
is supported. -
Defaults to true, so any task results will be cached.
options.value
[Optional] What to store as the cached result of the task.
-
Can be a function that returns an Object or a
Promise
that resolves to an Object. -
Can also be set to a string that will be picked of the task result file.
-
The result of this method is run through
JSON.stringify
and stored in a temp file for later retrieval. -
Defaults to
'contents'
which will grab the resulting file.contents and store them as a string.
Clearing the cache
If you find yourself needing to clear the cache, there is a handy dandy cache.clearAll()
method:
; gulp;
You can then run it with gulp clear
.
One-to-many caching
To support one-to-many caching in Your Gulp-plugin, you should:
- Use
clone
method, to save_cachedKey
property:
const outputFile1 = inputFile;const outputFile2 = inputFile; outputFile1contents = ...;outputFile2contents = ...; const outputFiles = outputFile1 outputFile2 ...;
- Or, do it manually:
const outputFiles = ... _cachedKey: inputFile_cachedKey ... _cachedKey: inputFile_cachedKey ...;
License
Copyright (c) 2014 - present Jacob Gable