Skip to content

[V5˖] Migrating your code to the V6

Georges.L edited this page Sep 29, 2017 · 6 revisions

⚠️ This wiki page applies to the V6 which has been released May 2017 ⚠️


Because the V6 is not backward compatible with the V5, here's a guide to help you to migrate your code:

Third party libraries are no longer required

⚠️ As of the V6, the third party libraries are no longer required but suggested. This list includes:

  • "predis/predis"
  • "mongodb/mongodb"
  • "phpfastcache/phpssdb"
  • "phpfastcache/couchdb"

🕐 Then:

The composer install/update was enough to pull dependencies

⏰ Now:

Specify your required "suggested" dependencies by hands: composer require phpfastcache/phpssdb

Type hint of Driver instances

🕐 Then:

Driver instances used to implements a phpFastCache\Cache\ExtendedCacheItemPoolInterface interface.

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');

if($instance instanceof \phpFastCache\Cache\ExtendedCacheItemPoolInterface)
{
    // Some code
}

⏰ Now:

This has been changed and they now implements a phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface interface

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');

if($instance instanceof \phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface)
{
    // Some code
}

Type hint of Item instances

🕐 Then:

Item instances used to implements a phpFastCache\Cache\ExtendedCacheItemInterface interface.

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');
$item = $instance->getItem('key');


if($item instanceof \phpFastCache\Cache\ExtendedCacheItemInterface)
{
    // Some code
}

⏰ Now:

This has been changed and it now returns a phpFastCache\Core\Item\ExtendedCacheItemInterface interface

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');
$item = $instance->getItem('key');


if($item instanceof \phpFastCache\Core\Item\ExtendedCacheItemInterface)
{
    // Some code
}

Catching \InvalidArgumentException

🕐 Then:

Code used to catch a \InvalidArgumentException interface.

namespace My\Custom\Project;

$instance = CacheManager::getInstance('Files');

try{
    $item = $instance->getItem(array());
}catch(\InvalidArgumentException $e){
    //Catched exception code
}

⏰ Now:

This has been changed you now MUST catch \phpFastCache\Exceptions\phpFastCacheInvalidArgumentException class

namespace My\Custom\Project;

$instance = CacheManager::getInstance('Files');

try{
    $item = $instance->getItem(array());
}catch(\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException $e){
    //Catched exception code
}

⚠️ Please note that \phpFastCache\Exceptions\phpFastCacheInvalidArgumentException implements \Psr\Cache\InvalidArgumentException as per PSR-6.

Catching \LogicException

🕐 Then:

Code used to catch a \LogicException.

namespace My\Custom\Project;

$instance = CacheManager::getInstance('Files');

try{
    $item = $instance->getItem(array());
}catch(\LogicException $e){
    //Catched exception code
}

⏰ Now:

This has been changed you now MUST catch \phpFastCache\Exceptions\phpFastCacheLogicException interface

namespace My\Custom\Project;

$instance = CacheManager::getInstance('Files');

try{
    $item = $instance->getItem(array());
}catch(\phpFastCache\Exceptions\phpFastCacheLogicException $e){
    //Catched exception code
}

Allowed characters in key identifier

⚠️ As of the V6, the following characters can not longer being a part of the key identifier: {}()/\@:

If you try to do so, an \phpFastCache\Exceptions\phpFastCacheInvalidArgumentException will be raised.

You must replace them with a safe delimiter such as .|-_

Cache clear method

The deprecated method phpFastCache\Cache\ExtendedCacheItemPoolInterface::clear() is now definitely removed.

🕐 Then:

In the V5 the method phpFastCache\Cache\ExtendedCacheItemPoolInterface::clear() was deprecated.

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');

if($instance instanceof \phpFastCache\Cache\ExtendedCacheItemPoolInterface)
{
    $instance->clear();
}

⏰ Now:

In the V6 we removed it. Use phpFastCache\Cache\ExtendedCacheItemPoolInterface::clean() instead.

namespace My\Custom\Project;


$instance = CacheManager::getInstance('Files');

if($instance instanceof \phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface)
{
    $instance->clean();
}

Mongodb driver has changed

⚠️ As of the V6, the Mongodb driver has been updated

🕐 Then:

In the V5 the driver was making use of of the deprecated class Mongo.

⏰ Now:

In the V6 we made an important change: We now make use of Mongodb Driver Only your code configuration will have to be updated, PhpFastCache manages all the abstract couch by itself.

Clone this wiki locally