Releases: patrixr/strapi-middleware-cache
v2.1.1
Middleware v2, complete rewrite by @stafyniaksacha ! 👏 👏
New configuration:
// config/middleware.js
module.exports = ({ env }) => ({
settings: {
/**
* @typedef {Object} UserMiddlewareCacheConfig
* @property {'mem'|'redis'=} type
* @property {boolean=} enabled
* @property {boolean=} logs
* @property {boolean=} populateContext
* @property {boolean=} populateStrapiMiddleware
* @property {boolean=} enableEtagSupport
* @property {boolean=} enableXCacheHeaders
* @property {boolean=} clearRelatedCache
* @property {boolean=} withKoaContext
* @property {boolean=} withStrapiMiddleware
* @property {string[]=} headers
* @property {number=} max
* @property {number=} maxAge
* @property {number=} cacheTimeout
* @property {(UserModelCacheConfig | string)[]=} models
* @property {Object=} redisConfig
*/
cache: {
enabled: true,
type: 'redis',
models: ['review'],
redisConfig: {
sentinels: [
{ host: '192.168.10.41', port: 26379 },
{ host: '192.168.10.42', port: 26379 },
{ host: '192.168.10.43', port: 26379 },
],
name: 'redis-primary',
},
},
},
});
Full Changelog: v1.5.0...v2.1.1
v1.5.0
v1.4.1
PATCH:
Support the new admin endpoints for strapi >= 3.4.0
Thanks @roelbeerens for reporting the issue and for suggesting a fix !
v1.4.0
NEW
Clearing related cache
By setting the clearRelatedCache to true, the middleware will inspect the Strapi models before a cache clearing operation to locate models that have relations with the queried model so that their cache is also cleared (this clears the whole cache for the related models). The ispection is performed by looking for direct relations between models and also by doing a deep dive in components, looking for relations to the queried model there too.
Many thanks to @julesrenaud for this contribution
v1.3.0
v1.2.0
v1.1.1
Fix the cache key for complex querystrings
Issue:
When the querystring includes params that are actually arrays (i.e. ?_where[0]=...&where[1]=... (See: https://strapi.io/documentation/v3.x/content-api/parameters.html#complex-queries), the current implementation just calls toString on the value (by way of template literals), which results in [object Object] in the cache key and hence breaking the cache.
v1.1.0
Cache entry point
By setting the populateContext
configuration to true
, the middleware will extend the Koa Context with an entry point which can be used to clear the cache from within controllers
// config/middleware.js
module.exports = ({ env }) => ({
settings: {
cache: {
enabled: true,
populateContext: true
models: ['post']
}
}
});
// controller
module.exports = {
async index(ctx) {
ctx.middleware.cache.store // A direct access to the cache engine
await ctx.middleware.cache.bust({ model: 'posts', id: '123' }); // Will bust the cache for this specific record
await ctx.middleware.cache.bust({ model: 'posts' }); // Will bust the cache for the entire model collection
await ctx.middleware.cache.bust({ model: 'homepage' }); // For single types, do not pluralize the model name
// ...
}
};
IMPORTANT: We do not recommend using this unless truly necessary. It is disabled by default as it goes against the non-intrusive/transparent nature of this middleware.