FOF30\Utils\CacheCleaner::clearCacheGroups PHP Method

clearCacheGroups() public static method

Clears the specified cache groups.
public static clearCacheGroups ( array $clearGroups, array $cacheClients = [0, 1] ) : void
$clearGroups array Which cache groups to clear. Usually this is com_yourcomponent to clear your component's cache.
$cacheClients array Which cache clients to clear. 0 is the back-end, 1 is the front-end. If you do not specify anything, both cache clients will be cleared.
return void
    public static function clearCacheGroups(array $clearGroups, array $cacheClients = array(0, 1))
    {
        $conf = \JFactory::getConfig();
        foreach ($clearGroups as $group) {
            foreach ($cacheClients as $client_id) {
                try {
                    $options = array('defaultgroup' => $group, 'cachebase' => $client_id ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache'));
                    $cache = \JCache::getInstance('callback', $options);
                    $cache->clean();
                } catch (\Exception $e) {
                    // suck it up
                }
            }
        }
    }

Usage Example

示例#1
0
 protected function onAfterSave()
 {
     // After adding/deleting a Download ID I have to clear the cache, otherwise I won't see the changes
     CacheCleaner::clearCacheGroups(array('com_ars'));
 }