How to use the pug.cache function in pug

To help you get started, we’ve selected a few pug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ladjs / cache-pug-templates / index.js View on Github external
fs.readFile(filename, 'utf8', (err, str) => {
      if (err) return this.config.logger.error(err);
      const options = { cache: true, filename };
      if (pug.cache[filename])
        return this.config.logger.warn(
          `${filename} was already cached in pug.cache`
        );
      // 
      setImmediate(() => {
        const template = pug.compile(str, options);
        if (this.config.cache) {
          debug(`caching ${filename}`);
          try {
            pug.cache[filename] = template;
          } catch (err) {
            this.config.logger.error(err);
          }
        } else {
          debug(
            `not caching ${filename} since \`cache\` option was set to \`false\``
github WagonOfDoubt / kotoba.js / app / src / controllers / generate.js View on Github external
const clearTemplateCache = () => {
  for (const prop of Object.keys(pug.cache)) {
    delete pug.cache[prop];
  }
};
github ladjs / cache-pug-templates / index.js View on Github external
if (stat.isDirectory()) {
        setImmediate(() => {
          this.cacheDirectory(filename);
        });
        return;
      }

      debug(`checking ${filename}`);

      if (path.extname(filename) !== '.pug') {
        debug(`${filename} did not have ".pug" extension`);
        return;
      }

      if (pug.cache[filename]) {
        debug(`${filename} was already cached in pug.cache`);
        return;
      }

      setImmediate(() => {
        this.writeCache(filename);
      });
    });
  }
github WagonOfDoubt / kotoba.js / app / src / controllers / generate.js View on Github external
const clearTemplateCache = () => {
  for (const prop of Object.keys(pug.cache)) {
    delete pug.cache[prop];
  }
};