From e843e582892b43db3084333c80d5954f44a6994a Mon Sep 17 00:00:00 2001 From: Christian Volmering Date: Sat, 25 Jul 2015 22:32:04 +0200 Subject: [PATCH] Added cache update if original file has been changed. Check if the original image has been changed since the cache file was created and if so, recreate it, otherwise send cached file. --- lib/quickthumb.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/quickthumb.js b/lib/quickthumb.js index c3f8a97..1ef5490 100644 --- a/lib/quickthumb.js +++ b/lib/quickthumb.js @@ -74,7 +74,17 @@ qt.static = function(root, options){ console.error(err); } else if (stats.isFile()){ - return sendfile(res, file); + // Check if the original image has been changed since the cache file + // was created and if so, recreate it, otherwise send cached file. + fs.stat(orig, function (err, origStats) { + if (err) { + console.error(err); + } else if (origStats.mtime.getTime() > stats.mtime.getTime()) { + return callback(); + } + + return sendfile(res, file); + }); } callback(); });