- 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
33 lines
810 B
Go
33 lines
810 B
Go
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)
|
|
}
|