Package Exports
- strapi-middleware-upload-plugin-cache
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (strapi-middleware-upload-plugin-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
strapi-middleware-upload-plugin-cache
Use case
- 'strapi-provider-upload-local' is in use for uploading assets via
Media Libraryin Strapi - 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') andkoa-static-cache(used in this middleware-plugin) can be found here
Installing
Using npm
npm install --save strapi-middleware-upload-plugin-cacheUsing yarn
yarn add strapi-middleware-upload-plugin-cacheSetup
For Strapi, add a middleware.js file within the config folder
e.g.
touch config/middleware.jscontaining
module.exports = ({ env }) => ({
settings: {
'upload-plugin-cache': {
enabled: true,
maxAge: 86400000
}
}
});
Starting Strapi in dev-mode should log the following:
[2020-12-30T21:37:57.560Z] debug [UploadCache] Initializing middleware ...
[2020-12-30T21:37:57.561Z] debug [UploadCache] Middleware initialized for endpoint='/uploads/(.*)' [maxAge=86400000]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 = ({ env }) => ({
settings: {
'upload-plugin-cache': {
enabled: true,
maxAge: 86400000,
dynamic: true,
lruCache: {
max: 1000
}
}
}
});