Programmatically expiring pages from cache

Permalink
Hi. I know I can use Cache::set or Cache::get to cache my own objects. But is there a way to force the eviction of a page from the C5 cache ?

The use case would be that the user approves page B. I catch the event. I know that page A depends on some attributes of page B and that it isn't up to date anymore, so I would like to evict page A from cache - like a Cache::delete, but I don't know arguments I would need.
I know I could use a short duration cache, but updates will occur only a few times a week, so I would like to avoid degrading performances.

Any idea if this is possible ?

View Replies: View Best Answer
hutman replied on at Permalink Best Answer Reply
hutman
You can do

use PageCache;
PageCache::purge($c);


Passing in a page ($c) will purge that page from the cache.
dangrth replied on at Permalink Reply
That simple ! :) Thank you, I'm still trying to get around the documentation from Concrete5 and still missing stuff like this...
tkart38 replied on at Permalink Reply
hi

if i make this in a controller
<?php
namespace Application\Controller\SinglePage;
use PageCache;
use Page;
use PageController;
class Purge extends PageController
{
   public function view(){
      $page = Page::getByID(171);
      //die(view);
      PageCache::purge($page);
      }
}


i've this error :

Cannot call abstract method Concrete\Core\Cache\Page\PageCache::purge()


i need to purge cache of some page programmatically
Jozzeh replied on at Permalink Reply
Jozzeh
Can you try :

$currentPage = Page::getCurrentPage();
$cache = PageCache::getLibrary();
$cache->purge($currentPage);
tkart38 replied on at Permalink Reply
thanks!
this work great!
tkart38 replied on at Permalink Reply
hi
How can i check if the page is on cache?
Thanks