Back to ApcuStorage class

Method gc

public bool
gc
()
Garbage collect expired cache data
Returns
  • bool
Since
  • 3.5
Class: ApcuStorage
Project: Joomla

Method gc - Source code

/**
 * Garbage collect expired cache data
 *
 * @return  boolean
 *
 * @since   3.5
 */
public function gc()
{
    $allinfo = apcu_cache_info();
    $keys = $allinfo['cache_list'];
    $secret = $this->_hash;
    foreach ($keys as $key) {
        if (isset($key['info'])) {
            // The internal key name changed with APCu 4.0.7 from key to info
            $internalKey = $key['info'];
        } elseif (isset($key['entry_name'])) {
            // Some APCu modules changed the internal key name from key to entry_name
            $internalKey = $key['entry_name'];
        } else {
            // A fall back for the old internal key name
            $internalKey = $key['key'];
        }
        if (strpos($internalKey, $secret . '-cache-')) {
            apcu_fetch($internalKey);
        }
    }
    return true;
}