npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-middleware-upload-plugin-cache

v2.1.0

Published

Adds middleware for caching uploaded assets when using @strapi/provider-upload-local

Downloads

456

Readme

strapi-middleware-upload-plugin-cache

Use case

  • @strapi/provider-upload-local is in use for uploading assets via Media Library in Strapi (default)
  • The need for configurable cache-control HTTP response headers (e.g. cache-control: max-age=1234) + ETag HTTP response header for each asset
  • More information and differences between koa-static (used in @strapi/provider-upload-local) and koa-static-cache (used in this middleware-plugin) can be found here

Installing

For Strapi 4.3+

Strapi 4.3 had breaking changes with asset organization through folders.

Make sure you are using at least v2.1.0 of this library with Strapi 4.3+!

Using npm

npm install strapi-middleware-upload-plugin-cache

Using yarn

yarn add strapi-middleware-upload-plugin-cache

For Strapi 4.0.0 - 4.2.X

Using npm

npm install [email protected]

Using yarn

yarn add [email protected]

For Strapi 3

Version 2.X.X+ of this library is NOT compatible with Strapi v3!

Please make sure to check out the Strapi v3 Docs for the installation & setup.

Setup

For Strapi, add a plugins.js file within the config folder

e.g.

touch config/plugins.js

containing

module.exports = {
  "upload-plugin-cache": {
    enabled: true,
    config: {
      maxAge: 86_400_000,
    },
  }
};

Starting Strapi in dev-mode should log the following:

[2022-02-22 22:22:22.222] debug: [upload-plugin-cache] Initializing ...
[2022-02-22 22:22:22.222] debug: [upload-plugin-cache] Middleware initialized for endpoint='/uploads/(.*)' [maxAge=300000]

Configuration Options

With the option dynamic: true files which are not cached on initializations are dynamically loaded. To avoid OOM errors a LRU-cache can be used. For config options of lru-cache use these docs and insert them at lruCache.

module.exports = {
  "upload-plugin-cache": {
    enabled: true,
    config: {
      maxAge: 86_400_000,
      dynamic: true,
      lruCache: {
        max: 1000
      },
    },
  }
};

Resources

Links