Skip to content

Commit

Permalink
add: option to set cacheDir
Browse files Browse the repository at this point in the history
  • Loading branch information
joeybaker committed Nov 5, 2015
1 parent d00be99 commit 12ff7fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Standard Options:
If you're running multiple persistify instances from the same directory, use this to
differentiate them.
--cache-dir [default: node_modules/flat-cache/.cache]
By default, the cache is saved to the default directory that flat-cache sets. This sets a custom directory for the cache files.
```
## Examples
Expand Down
5 changes: 4 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ function run() {
var _argv = process.argv.slice( 2 );
var persistifyArgs = subarg( _argv, {
alias: {
'n': 'never-cache'
'n': 'never-cache',
'd': 'cache-dir'
}
} );

var watch = persistifyArgs.watch;
var recreate = persistifyArgs.recreate;
var neverCache = persistifyArgs[ 'never-cache' ];
var cacheId = persistifyArgs[ 'cache-id' ];
var cacheDir = persistifyArgs[ 'cache-dir' ];

var w = require( '../' )( null, {
cacheId: cacheId,
cacheDir: cacheDir,
command: _argv.join( ' ' ),
neverCache: neverCache,
watch: watch,
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ module.exports = function ( browserifyOpts, opts, argv ) {

var id = 'persistify_' + hash( process.cwd() + trim( opts.cacheId ) );
var depsCacheId = 'deps-cx-' + id;
var cacheDir = opts.cacheDir;

var flatCache = require( 'flat-cache' );
var fileEntryCache = require( 'file-entry-cache' );

if ( opts.recreate ) {
flatCache.clearCacheById( id );
flatCache.clearCacheById( depsCacheId );
flatCache.clearCacheById( id, cacheDir );
flatCache.clearCacheById( depsCacheId, cacheDir );
}
// load the cache with id
var cache = flatCache.load( id );
var cache = flatCache.load( id, cacheDir );

// load the file entry cache with id, or create a new
// one if the previous one doesn't exist
var depsCacheFile = fileEntryCache.create( depsCacheId );
var depsCacheFile = fileEntryCache.create( depsCacheId, cacheDir );

var ignoreCache = false;

Expand Down

0 comments on commit 12ff7fa

Please sign in to comment.