Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Caching isFile results, ref #1
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed Aug 2, 2016
1 parent cf24c1d commit e6ad15d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/util/isFile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
var debug = require('debug')('keystone:email');
var fs = require('fs');

var cache = {};

function isFile (path) {
if (cache[path] !== undefined) {
return cache[path];
}
debug('isFile "%s"', path);
try {
var stat = fs.statSync(path);
return stat.isFile();
cache[path] = stat.isFile();
} catch (e) {
return false;
cache[path] = false;
}
return cache[path];
}

module.exports = isFile;

0 comments on commit e6ad15d

Please sign in to comment.