Skip to content

Commit c5cd34b

Browse files
committed
feat: enable caching by default
1 parent 2dafe97 commit c5cd34b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,13 @@ Promise
352352

353353
### Cache Pug Templates
354354

355+
Out of the box, templates are cached as they are compiled (e.g. as emails are sent, the template they're using is cached). However these templates are not cached in-advance, so the first emails sent of each template will be slower to send.
356+
355357
We strongly suggest to pre-cache your templates with [cache-pug-templates][] (if you're using the default [Pug][] template engine).
356358

357359
If you do not do this, then your Pug templates will re-compile and re-cache every time you deploy new code and restart your app.
358360

359-
Note that you will need to specify the `views` option to your `new CachePugTemplates({ views: '...' });` instance, with `views` being a file path (Array or String) to your email template directory.
361+
Note that you will need to specify the `views` option to your `new CachePugTemplates({ views: '...' });` instance, with `views` being a file path (Array or String) to your email template directory. See [cache-pug-templates][] documentation for more information.
360362

361363
### Localization
362364

@@ -681,6 +683,7 @@ For a list of all available options and defaults [view the configuration object]
681683
* `map` (Object) - a template file extension mapping, defaults to `{ hbs: 'handlebars', njk: 'nunjucks' }` (this is useful if you use different file extension naming conventions)
682684
* `engineSource` (Object) - the default template engine source, defaults to [consolidate][]
683685
* `locals` (Object) - locals to pass to templates for rendering
686+
* `cache` (Boolean) - defaults to `false` for `development` and `test` environments, and `true` for all others (via `process.env.NODE_ENV`), whether or not to cache templates
684687
* `pretty` (Boolean) - defaults to `true`, but is automatically set to `false` for subject templates and text-based emails
685688
* `message` (Object) - default [Nodemailer message object][nodemailer-message-object] for messages to inherit (defaults to an empty object `{}`)
686689
* `send` (Boolean) - whether or not to send emails, defaults to `false` for `development` and `test` environments, and `true` for all others (via `process.env.NODE_ENV`) (**NOTE: IF YOU ARE NOT USING `NODE_ENV` YOU WILL NEED TO MANUALLY SET THIS TO `true`**)

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Email {
6363
},
6464
// locals to pass to templates for rendering
6565
locals: {
66+
// turn on caching for non-development environments
67+
cache: !['development', 'test'].includes(env),
6668
// pretty is automatically set to `false` for subject/text
6769
pretty: true
6870
}

0 commit comments

Comments
 (0)