Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Releases: patrixr/strapi-middleware-cache

v2.1.1

19 Oct 06:44
298c5b0
Compare
Choose a tag to compare

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

25 Feb 02:12
Compare
Choose a tag to compare

Updates

  • Bust /count endpoint
  • Update admin endpoints

Thanks @stafyniaksacha for the contribution !

v1.4.1

04 Feb 07:29
b32979a
Compare
Choose a tag to compare

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

29 Jan 04:54
81f2ced
Compare
Choose a tag to compare

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

26 Jan 02:38
38d2222
Compare
Choose a tag to compare

Added features

v1.2.0

10 Jan 03:14
8477028
Compare
Choose a tag to compare

ADD: cache entry point to strapi.middleware

Thanks @meck93 for the contribution !

v1.1.1

10 Dec 06:34
300b16a
Compare
Choose a tag to compare

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.

Thanks to @bartzy for the fix (#28)

v1.1.0

02 Dec 03:58
b8c1e7b
Compare
Choose a tag to compare

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.

v1.0.11

16 Nov 04:23
9fa09f6
Compare
Choose a tag to compare

Cache is now automatically busted when a record is published on unpublished via the new Strapi Draft API

v1.0.10

14 Oct 06:42
9dac9da
Compare
Choose a tag to compare

Bug fix: Admin UI changes would not bust the cache for non-standard "s" pluralizations (e.g academy/academies)

Reported by #19