feat(16.2-07): purge the host site cache after a category admin update
- classes.SiteCachePurger posts {kind, slug} with a bearer token to
golem15.journal.site_cache.purge_url, 2 s timeout, logged, never fails a save
- PurgeSiteCacheAfterCommit runs it through lagoon.AfterCommit
- Boot builds and publishes the purger from the two config keys
- categories FormAfterUpdate registers the purge; Postgres test proves
one authorized request after the commit
This commit is contained in:
32
controllers/site_cache.go
Normal file
32
controllers/site_cache.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.golem15.com/golem15/sm-journal-plugin/classes"
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
)
|
||||
|
||||
// purgeSiteCache registers a site cache purge for one saved entity to run
|
||||
// after the save transaction commits. Without a published
|
||||
// *classes.SiteCachePurger (no purge configured) or outside a save
|
||||
// transaction it does nothing.
|
||||
func purgeSiteCache(ctx context.Context, app func() *backpack.App, kind, slug string) {
|
||||
if app == nil {
|
||||
return
|
||||
}
|
||||
a := app()
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
purger, ok := a.Lookup[*classes.SiteCachePurger]()
|
||||
if !ok || purger == nil {
|
||||
return
|
||||
}
|
||||
tx, ok := cabana.TxFromContext(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
classes.PurgeSiteCacheAfterCommit(ctx, tx, purger, kind, slug)
|
||||
}
|
||||
Reference in New Issue
Block a user