Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
nuxt-multi-cache
Advanced tools
This module provides several layers of server-side caching for your Nuxt 3 app:
Version 1.x (which is in maintenance mode) supports Nuxt 2.
Does your Nuxt app serve thousands of pages from a CMS? Does it have tens of thousands of requests per day? Does the data change frequently? Does rendering a single page require fetching data from multiple APIs? If you've answered any of these questions with "yes", then this module might be for you.
I work fulltime on building frontends with Nuxt for large CMS sites. Rendering a single page might require up to 10 API calls to get all the data: Menu, footer, translations, route, page data, user state, additional data... It all adds up and doing that for every request can quickly become a bottleneck. Maybe you can work around this problem by getting all the data in a single API call, but I didn't like to have components dependent on global state.
Instead my solution was to cache the API responses locally on the server. Either for a fixed amount of time, like 5 minutes, or until the cache entry is being invalidated. In addition, I cache components that appear on most pages, like menu or footer.
The hardest thing in IT is cache invalidation, so I also added a way to invalidate cache entries by key or using cache tags.
Use the <RenderCacheable>
wrapper component to cache the markup of the default
slot:
<template>
<div>
<RenderCacheable cache-key="navbar_de" :max-age="3600">
<Navbar />
</RenderCacheable>
</div>
</template>
The component is only rendered once and its markup cached. Afterwards the markup is directly returned.
Cache rendered pages or custom API responses:
<script lang="ts" setup>
useRouteCache((route) => {
// Mark the page as cacheable for 1 hour and add a cache tag.
route.setCacheable().setMaxAge(3600).addTags(['page:2'])
})
</script>
Manage the cacheability for the current response. This will set the correct cache control and cache tags headers for Cloudflare, Fastly and other cache providers:
<script lang="ts" setup>
useCDNHeaders((helper) => {
helper
.public()
.setNumeric('maxAge', 3600)
.setNumeric('staleWhileRevalidate', 21600)
.set('mustRevalidate', true)
.addTags(['page:2', 'image:342'])
})
</script>
The state is managed inside the current request and can be changed for the entire duration of the request. The headers are generated right before the response is sent.
The optional API provides endpoints to manage the caches.
FAQs
SSR route, component and data cache for Nuxt.js
The npm package nuxt-multi-cache receives a total of 6,418 weekly downloads. As such, nuxt-multi-cache popularity was classified as popular.
We found that nuxt-multi-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.