Programmatically expiring pages from cache

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
You can do

use PageCache;

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

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

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
Can you try :

$currentPage = Page::getCurrentPage();
$cache = PageCache::getLibrary();
tkart38 replied on at Permalink Reply
this work great!
tkart38 replied on at Permalink Reply
How can i check if the page is on cache?
tkart38 replied on at Permalink Reply
i've found a little problem, with full cache page, if i use this:
$currentPage = Page::getCurrentPage();
$cache = PageCache::getLibrary();

don't clear the cache of content block, i need to use flush() but this clear the cache of all pages.

For solve the problem i use this :
$pageblock = $page_c5->getBlocks('Main');
                foreach ($pageblock as $bi) {
                        $block_id = $bi->getBlockTypeID();
         $Block = BlockType::getByID($block_id);
         $Block ->clearCache();

but clear the cache for all the block of this type.

any ideas for clear only the cache of the block in this page?

i'm tryng with Concrete\Core\Block\Block
refreshBlockOutputCache( )
refreshCache( )
refreshCacheAll( )