Jump to content

Regenerate cache when page is saved or published.


Zeka
 Share

Recommended Posts

Hi.

I'm looking for the right way to regenerate page cache when a page is saved or published so it has cached version when a user hit on the frontend. All that I can think about is to send get a request like:

$this->wire->addHookAfter('Pages::saved(template=post), Pages::published(template=post)', $this, 'clearCacheFile');


public function clearCacheFile($event) {
		$page = $event->arguments[0];
		$pages = $event->wire('pages');

		....

		if(count($clearPages)) {
			$this->wire('modules')->get('PageRender')->clearCacheFilePages($clearPages, $page);
			$this->message(sprintf($this->_('Cleared cache file for %d page(s)'), count($clearPages)), Notice::debug);
		}

		$http = new WireHttp();
		$http->get($page->httpUrl);

	}

But I'm not sure is that good way and what pitfalls it would have? 

Link to comment
Share on other sites

17 hours ago, Zeka said:

But I'm not sure is that good way and what pitfalls it would have? 

Since you have an array(ish) $clearPages, it looks like you want to recreate the cache for depending pages too (blog categories/tags pages etc.?) so I'd guess you'd have to make a request for each of those. It might become a runtime issue if you have multiple complex pages to render, but the worst that could happen is that rendering breaks at some point and the first request to an uncached page is slower.

  • Like 1
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...