const fs = require('fs');
const {promisify} = require('util');

const stat = promisify(fs.stat);

const checkCacheExpiry = (path, ttl) =>
    stat(path).then(stats => {

        if (new Date(stats.mtime).getTime() + ttl < Date.now()) {

            throw new Error('Cache has expired.');

        }

        return stats;

    });

module.exports = checkCacheExpiry;

@@ -316,16 +316,102 @@
 stats;%0A%0A
+    %7D)%0A        .catch(() =%3E %7B%0A%0A            throw new Error('Cache is missing.');%0A%0A    
     %7D);%0A

Throw error when cache is missing.