Skip to content

Commit 0797da9

Browse files
Merge pull request #107 from Four-Lights-NL/fix/cache-invalidation-cascade
fix: cache invalidation cascade
2 parents 9c43d0a + cd5d08e commit 0797da9

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.12.0] - 2025-11-20
4+
5+
### Fixed
6+
7+
- Cache invalidation now properly triggers when publishing an document ([#107](https://github.com/Four-Lights-NL/strapi-plugin-deep-populate/pull/107)) (Thomas Rijpstra)
8+
39
## [1.11.1] - 2025-11-19
410

511
### Changed
@@ -275,3 +281,5 @@ _:seedling: Initial release._
275281
[1.11.0]: https://github.com/Four-Lights-NL/strapi-plugin-deep-populate/releases/tag/v1.11.0
276282

277283
[1.11.1]: https://github.com/Four-Lights-NL/strapi-plugin-deep-populate/releases/tag/v1.11.1
284+
285+
[1.12.0]: https://github.com/Four-Lights-NL/strapi-plugin-deep-populate/releases/tag/v1.12.0

server/src/register.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ export default async ({ strapi }) => {
8787
const result = await next()
8888
if (!result) return result
8989

90-
if (["create", "update"].includes(context.action)) {
90+
if (["create", "update", "publish"].includes(context.action)) {
9191
const { documentId, publishedAt, locale } = result
9292
const status = publishedAt !== null ? "published" : "draft"
93+
const refreshCache = useCache && ["update", "publish"].includes(context.action)
9394

94-
if (useCache && context.action === "update")
95-
await cacheService.clear({ ...context.params, contentType: context.uid })
95+
if (refreshCache) await cacheService.clear({ ...context.params, status, contentType: context.uid })
9696

9797
if (useCache || returnDeeplyPopulated) {
9898
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status, locale })

server/src/services/cache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ export default ({ strapi }: { strapi: Core.Strapi }) => ({
7676
return retval
7777
},
7878

79-
async refreshDependents(documentId: string) {
79+
async refreshDependents(documentId: string, status?: "draft" | "published" | undefined) {
8080
// Get all cached entries that are dependent on the document
81-
const entries = await strapi
81+
let entries = await strapi
8282
.documents("plugin::deep-populate.cache")
8383
.findMany({ filters: { dependencies: { $contains: documentId } }, fields: ["documentId", "params"] })
8484

85+
// Filter on requested status
86+
if (status !== undefined) entries = entries.filter((entry) => entry.params.status === status)
87+
8588
// Delete the cached entries
8689
const deleted = await strapi.db.query("plugin::deep-populate.cache").deleteMany({
8790
where: {

server/src/services/deep-populate/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,7 @@ export default async function populate(params: PopulateParams) {
375375
populated.__deepPopulated = true
376376
populated.__deepPopulateConfig = config
377377

378-
return { populate: populated, dependencies: [...resolvedRelations.keys()] }
378+
// Remove content-types from resolvedRelations
379+
const dependencies = [...resolvedRelations.keys()].filter((r) => !r.startsWith("api::"))
380+
return { populate: populated, dependencies }
379381
}

0 commit comments

Comments
 (0)