[V9˖] Cache contract - PHPSocialNetwork/phpfastcache GitHub Wiki

Important notice


The cache contract is fondamentally the same exact concept and class than the former known Cache Conditional (Wiki Doc).

However the class has changed its name:

The class \Phpfastcache\Helper\CacheConditionalHelper is now deprecated *, use \Phpfastcache\CacheContract instead.

This new class \Phpfastcache\CacheContract works exactly the same as before and nothing changed except its name and namespace.

* (but still usable with an E_USER_DEPRECATED notice)

:new: Callable syntax available as of the V9


However, as of the V9 this class is now also callable, this means you don't need to call the get() method if you want (via a simple __invoke() implementation):

// The old and still working known syntax
$value = (new CacheContract($cacheInstance))->get($cacheKey, static function() use ($testHelper){
        $testHelper->assertPass('The CacheContract class is callable via __invoke()');
        return null;
    });

// The new possible syntax: "->get" has been removed
$value = (new CacheContract($cacheInstance))($cacheKey, static function() use ($testHelper){
        $testHelper->assertPass('The CacheContract class is callable via __invoke()');
        return null;
    });

The both syntax are now possible, however the callable syntax would allow you some more complex implementation on projects that need a callable instead of an object. Note that the parameters of the callable syntax are EXACTLY the same as the get() method, in fact, internally, the __invoke() forward the call to the get() method and returns its returned value.