As of the V3 the bundle is absolutely not compatible with previous versions.u the smoothest migration possible. One of the biggest change is the Phpfastcache's dependency which is not set to the v7 which it not backward compatible at all. Also please note that the bundle is currently in development and under a massive code rewrite. :warning: The code of the v3 is NOT production or development ready ATM.
composer require phpfastcache/phpfastcache-bundle
# PhpFastCache configuration
php_fast_cache:
twig_driver: "filecache" # This option must be a valid declared driver, in our example: "filecache"
twig_block_debug: false # This option will wrap CACHE/ENDCACHE blocks with block debug as HTML comment
drivers:
filecache:
type: Files
parameters:
path: "%kernel.cache_dir%/phpfastcache/"
- More examples in Docs/Example/app/config
$bundles[] = new Phpfastcache\Bundle\phpFastCacheBundle();
- See the file Docs/Example/app/AppKernel.php for more information.
Caching data in your controller:
public function indexAction(Request $request)
{
$cache = $this->get('phpfastcache')->get('filecache');
$item = $cache->getItem('myAppData');
if (!$item->isHit() || $item->get() === null) {
$item->set('Wy app has now superpowers !!')->expiresAfter(3600);//1 hour
$cache->save($item);
}
// replace this example code with whatever you need
return $this->render('default/index.html.twig', [
'myAppData' => $item->get(),
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
]);
}
Or in your template:
<div>
{#
* 'myrandom6' Is your cache key identifier, must be unique
* 300 Is the time to live (TTL) before the cache expires and get regenerated
#}
{% cache 'myrandom6' 300 %}
<textarea>
<!-- Some heavy stuff like Doctrine Lazy Entities -->
{% for i in 1..1000 %}{{ random() }}{% endfor %}
</textarea>
{% endcache %}
</div>
Found an issue or had an idea ? Come here here and let us know !