PawelGIX Posted January 19, 2022 Share Posted January 19, 2022 How to programmatically clear the page cache? I have a page that uses URL Segments. Based on the value of the URL Segment, the content of the page varies. From what I can see, the cache can handle it without a problem. But I have another question. I need to create an API that will clean the cache of selected pages - based on the value of URL Segments or some other value. Is there an API that will allow me to manage the page cache generated by PW? 1 Link to comment Share on other sites More sharing options...
Gideon So Posted January 20, 2022 Share Posted January 20, 2022 Hi @PawelGIX Sorry. Wrong answer. Gideon Link to comment Share on other sites More sharing options...
hassanizhar Posted February 17 Share Posted February 17 In ProcessWire, you can clear the page cache programmatically using the $cache API object. To clear the cache for a specific page, you can use the clear method of the $cache object, passing in the page's ID as a parameter. For example: php Copy code $cache = $pages->getCache(); $cache->clear($page->id); If you want to clear the cache for multiple pages, you can use a selector to retrieve the pages and loop through them, clearing the cache for each page: php Copy code $pages = $pages->find('template=your_template'); foreach($pages as $page) { $cache->clear($page->id); } You can also clear the entire page cache by calling the $cache->deleteAll() method: php Copy code $cache = $pages->getCache(); $cache->deleteAll(); To clear the cache for pages based on the value of URL segments or some other value, you can use a selector to retrieve the pages that match the criteria and then clear the cache for each page in the same way as shown above. Keep in mind that clearing the page cache can have performance implications, so you should use it judiciously and only when necessary. Link to comment Share on other sites More sharing options...
szabesz Posted February 18 Share Posted February 18 It looks to me that the post above was generated by ChatGPT. It begins with "In ProcessWire,..." and ends in "Keep in mind that...". I doubt that copy/pasting ChatGPT results is a good way of discussion. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now