Jump to content

Cache clear when saving page versus saving just one field on the page


AAD Web Team
 Share

Recommended Posts

In our page template cache settings we have, "Clear cache for saved page and parents", which works as expected when using ProcessWire (3.0.200) interactively.

When we manipulate pages with the same template from the API though we get this:

$page->save(); // Cache clear happens as expected

$page->save('my_field'); // Cache clear is not triggered – it's as if the page has not been saved (though the field has been saved correctly).

$page->setAndSave('my_field', $value); // Cache clear is not triggered

Is this the expected behaviour? If so, could the $page->save() documentation be updated to mention this difference?

  • Like 2
Link to comment
Share on other sites

ProcessWire is particular about the difference between saving pages and saving individual fields. In this case, only Pages::save and Pages::delete trigger the hook: https://github.com/processwire/processwire/blob/master/wire/modules/PageRender.module#L74. I agree this difference is pretty underdocumented.

You can probably hook up your desired behaviour somewhat like this in ready.php:

$this->addHookAfter("Pages::saveField", function(HookEvent $event)
{
    modules()->get('PageRender')->clearCacheFile($event);
});

I haven’t tested it but the relevant hook arguments should be the same, i. e. the Page is argument 0, so it might work?

There is also Pages::savedPageOrField for when you want to make your own hooks trigger regardless of how the page was modified.

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...