Skip to content

[V4] Migrating your code to the V5

Georges edited this page Jun 18, 2016 · 2 revisions

Because the V5 is not backward compatible with the V4 we will help you to migrate your code:

Extending phpFastCache:

🕐 Then:

namespace My\Custom\Project;
use phpFastCache\Core\phpFastCache;

/**
 * Class Cache
 */
class Cache extends phpFastCache
{

}

⏰ Now:

namespace My\Custom\Project;
use phpFastCache\Proxy\phpFastCacheAbstractProxy;

/**
 * Class Cache
 */
class Cache extends phpFastCacheAbstractProxy
{

}

See examples/extendedPhpFastCache.php for more informations

Get/Set uses:

🕐 Then:

namespace My\Custom\Project;
use phpFastCache\Core\phpFastCache;

$cache = phpFastCache();
// or
$cache = __c();

$myCacheItem = $cache->get("myKey");

if($myCacheItem === null){
  $myCacheItem = database_operation();
  $cache->set("myKey", $myCacheItem, 600);
}


$template['myCacheItemData'] = $myCacheItem;

⏰ Now:

namespace My\Custom\Project;

$config = [
  'path' => 'An\absolute\path',
];
$cache = CacheManager::getInstance('Files', $config);
// or
$cache = CacheManager::Files($config);

$myCacheItem = $cache->getItem("myKey");

if(!$myCacheItem->isHit()){
  $myCacheItem->set(database_operation());
  $cache->save($myCacheItem);
}

$template['myCacheItemData'] = $myCacheItem->get();

Cache clearing:

🕐 Then:

namespace My\Custom\Project;
use phpFastCache\Core\phpFastCache;

$cache = phpFastCache();
// or
$cache = __c();

$cache->clean();

⏰ Now:

namespace My\Custom\Project;

$config = [
  'path' => 'An\absolute\path',
];
$cache = CacheManager::getInstance('Files', $config);
// or
$cache = CacheManager::Files($config);

$myCacheItem = $cache->clear();

Search system:

The search system has been removed in favor of Tags features. Remember that the cache must NOT be considered as a search engine like Solr, Sphynx etc.

See examples/tagsMethods.php for more information

Clone this wiki locally