feat(16.2-07): purge the host site cache on every admin post and category write
- posts: FormAfterCreate/Update purge after the content_html translations, new FormAfterDelete; categories: FormAfterCreate and FormAfterDelete - NewSiteCachePurger refuses half configuration, non-http(s) URLs, user info, fragments, http to a non-loopback host and tokens under 32 chars; Boot logs the endpoint host and path once - TestPostsAdminPurgesSiteCache smoke test - README: Configuration section (keys, contract, timing, scope), API rows
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/sm-journal-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-journal-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
@@ -60,14 +61,31 @@ func (categoriesAdminController) FormBeforeUpdate(ctx context.Context, model any
|
||||
return prepareCategoryWrite(cat)
|
||||
}
|
||||
|
||||
// FormAfterCreate purges the host site's page caches once the save
|
||||
// transaction commits (G-16.2-2, D-19).
|
||||
func (c categoriesAdminController) FormAfterCreate(ctx context.Context, model any) error {
|
||||
return c.purgeAfterCommit(ctx, model)
|
||||
}
|
||||
|
||||
// FormAfterUpdate purges the host site's page caches once the save
|
||||
// transaction commits (G-16.2-2, D-19).
|
||||
func (c categoriesAdminController) FormAfterUpdate(ctx context.Context, model any) error {
|
||||
return c.purgeAfterCommit(ctx, model)
|
||||
}
|
||||
|
||||
// FormAfterDelete purges the host site's page caches once the delete
|
||||
// commits.
|
||||
func (c categoriesAdminController) FormAfterDelete(ctx context.Context, model any) error {
|
||||
return c.purgeAfterCommit(ctx, model)
|
||||
}
|
||||
|
||||
func (c categoriesAdminController) purgeAfterCommit(ctx context.Context, model any) error {
|
||||
cat, ok := model.(*models.Category)
|
||||
if !ok || cat == nil {
|
||||
return errors.New("categories admin: form model is not a category")
|
||||
}
|
||||
purgeSiteCache(ctx, c.app, "category", cat.Slug)
|
||||
purger, tx := siteCachePurger(ctx, c.app)
|
||||
classes.PurgeSiteCacheAfterCommit(ctx, tx, purger, "category", cat.Slug)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -95,6 +113,8 @@ var (
|
||||
_ pact.AdminRecordSource = categoriesAdminController{}
|
||||
_ pact.FormBeforeCreate = categoriesAdminController{}
|
||||
_ pact.FormBeforeUpdate = categoriesAdminController{}
|
||||
_ pact.FormAfterCreate = categoriesAdminController{}
|
||||
_ pact.FormAfterUpdate = categoriesAdminController{}
|
||||
_ pact.FormAfterDelete = categoriesAdminController{}
|
||||
_ cabana.FieldRelationProvider = categoriesAdminController{}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user