Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass cache option to eta engine #251

Merged
merged 3 commits into from
Aug 25, 2021
Merged

Pass cache option to eta engine #251

merged 3 commits into from
Aug 25, 2021

Conversation

erming
Copy link
Contributor

@erming erming commented Aug 23, 2021

Hello maintainers,

While using this plugin with the https://github.com/eta-dev/eta template engine, I noticed that NODE_ENV=production never cached the templates.

After some digging I found the culprit:

  • point-of-view never sends the { cache: true } option to the eta engine

This pull request solves this.

app.register(require("point-of-view"), {
  engine: {
    eta: require("eta")
  },
  options: {
    cache: true // This variable is now set by NODE_ENV=production
  }
});

It can also be enabled by passing production: true to the engine.

Benchmark

Rendering a simple template with NODE_ENV=production

// index.js
app.register(require("point-of-view"), {
  engine: {
    eta: require("eta")
  }
});
app.get("/", async (req, res) => {
  res.view("view", {
    items: ["a", "b", "c"]
  });
});

// view.eta
<ul class="items">
  <% for (let item of it.items) { %>
    <li><%= item %></li>
  <% } %>
</ul>

Performance improvements:

$ autocannon -c 100 -d 5 -p 10 localhost:8000

— Before:   32k requests in 5.03s,  7.4 MB read
— After:   252k requests in 5.03s, 60.4 MB read

Checklist

@Fdawgs
Copy link
Member

Fdawgs commented Aug 23, 2021

LGTM.

For reference for other reviewers: https://eta.js.org/docs/api/configuration

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test like this one to verify this new default value?

test('fastify.view with eta engine and custom cache', t => {

@erming
Copy link
Contributor Author

erming commented Aug 24, 2021

Could you add a test like this one to verify this new default value?

test('fastify.view with eta engine and custom cache', t => {

Done!

@climba03003 climba03003 requested a review from Eomm August 25, 2021 07:02
Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants