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 ?

 
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
tkart38 replied on at Permalink Reply
hi
i've found a little problem, with full cache page, if i use this:
$currentPage = Page::getCurrentPage();
$cache = PageCache::getLibrary();
$cache->purge($currentPage);


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( )