Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

The symfony 3/Flex bundle for PhpFastCache integrating a phpfastcache service, a twig cache tag and a powerfull cache profiler integrated to the symfony profile

License

Notifications You must be signed in to change notification settings

PHPSocialNetwork/phpfastcache-bundle

Repository files navigation

Code Climate Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads License

Symfony Flex PhpFastCache Bundle

⚠️ Please note that the V3 is a major (BC breaking) update of the PhpFastCache Bundle !

As of the V3 the bundle is absolutely not compatible with previous versions.To ensure you the smoothest migration possible, please check the migration guide in the Resources/Docs directory. One of the biggest change is the Phpfastcache's dependency which is not set to the v7 which it not backward compatible at all.

👍 Step 1: Include phpFastCache Bundle in your project with composer:

composer require phpfastcache/phpfastcache-bundle

🚧 Step 2: Setup your config/packages/phpfastcache.yaml to configure your cache(s) instance(s)

# PhpFastCache configuration
phpfastcache:
    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/"

🚀 Step 3: Accelerate your app by making use of PhpFastCache service

Caching data in your controller:

public function indexAction(Request $request, Phpfastcache $phpfastcache)
{
    $cache = $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>

💥 phpFastCache Bundle support

Found an issue or had an idea ? Come here here and let us know !

About

The symfony 3/Flex bundle for PhpFastCache integrating a phpfastcache service, a twig cache tag and a powerfull cache profiler integrated to the symfony profile

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published