2017 © Pedro Peláez
 

symfony-bundle phpfastcache-bundle

Phpfastcache Bundle for Symfony integration

image

phpfastcache/phpfastcache-bundle

Phpfastcache Bundle for Symfony integration

  • Sunday, May 27, 2018
  • by khoaofgod
  • Repository
  • 3 Watchers
  • 15 Stars
  • 5,710 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 29 Versions
  • 26 % Grown

The README.md

Code Climate Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads License, (*1)

Symfony Flex PhpFastCache Bundle

:warning: 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., (*2)

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

composer require phpfastcache/phpfastcache-bundle

:construction: 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/"

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

Caching data in your controller:, (*3)

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:, (*4)

<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>

:computer: CLI command interactions

As of the V3, some command-line tools were introduced, mostly for CRUD-like operations., (*5)

GET operation
php bin/console phpfastcache:get filecache cacheKey

This will display the content of a cache item if it eventually exists., (*6)

SET operation
php bin/console phpfastcache:get filecache cacheKey '{"a": 14}' 300 -a 1

This will set the content of a cache item.\ The TTL (300), in seconds, is optional and take the default value filled in your configuration file.\ The auto-type-cast option "-a"_ (enabled by default) will let allows you to automatically type cast your variable: - false and true will be respectively converted to _boolean. - 1337 and 1337.666 will be respectively be converted to integer or float. - null will be converted to null. - {"a": 14} will be converted to an associative array using a JSON detection - a regular string will remains unchanged and stays a string, (*7)

You can obviously disable this behavior by turning off the auto-type-cast option: -a 0, (*8)

DELETE operation
php bin/console phpfastcache:del filecache cacheKey

This will delete the specified cache item., (*9)

CLEAR operation
php bin/console phpfastcache:clear filecache
# OR to clear every caches:
php bin/console phpfastcache:clear

This will clear a single cache instance if specified or all the configured cache instances otherwise., (*10)

:bulb: Introducing Cacheable Responses (V3 only)

As of the V3 there's a new, easier and cleaner way to setup HTTP cache to decrease your server bandwidth along with your CPU load: Cacheable Responses. And it's pretty easy to implement:, (*11)

    /**
     * @Route("/cached", name="cached")
     */
    public function cachedAction(Phpfastcache $phpfastcache, Request $request): Response
    {
        return (new CacheableResponse($phpfastcache->get('filecache'), $request))->getResponse('cache_key', 3600, function () {
            return new Response('Random bytes: ' . \random_bytes(255));
        });
    }

CacheableResponse is provided by \Phpfastcache\Bundle\Response\CacheableResponse. This class will handle responses headers (cache-control, etag, etc...) and http status (304 Not modified)., (*12)

:boom: phpFastCache Bundle support

Found an issue or had an idea ? Come here here and let us know !, (*13)

The Versions

09/05 2018

3.0.0-alpha3

3.0.0.0-alpha3 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

02/05 2018

2.x-dev

2.9999999.9999999.9999999-dev http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

02/05 2018

2.0.3

2.0.3.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

16/02 2018

1.x-dev

1.9999999.9999999.9999999-dev http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

16/02 2018

1.0.5

1.0.5.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

16/02 2018

2.0.2

2.0.2.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

16/02 2018

2.0.1

2.0.1.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

01/07 2017

2.0.0

2.0.0.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

26/12 2016

1.0.4

1.0.4.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

26/12 2016

2.0.0-rc1

2.0.0.0-RC1 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

07/12 2016

2.0.0-beta2

2.0.0.0-beta2 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

04/12 2016

1.0.3

1.0.3.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

03/12 2016

1.0.2

1.0.2.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

18/09 2016

1.0.1

1.0.1.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

18/09 2016

2.0.0-beta

2.0.0.0-beta http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

20/08 2016

2.0.0alpha

2.0.0.0-alpha http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

20/08 2016

2.0.0-alpha

2.0.0.0-alpha http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

04/08 2016

1.0.0

1.0.0.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

07/06 2016

0.0.1

0.0.1.0 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

19/05 2016

0.0.1-beta1

0.0.1.0-beta1 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

16/05 2016

0.0.1-alpha2

0.0.1.0-alpha2 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache

15/05 2016

0.0.1-alpha1

0.0.1.0-alpha1 http://www.phpfastcache.com

PHP Bundle

  Sources   Download

MIT

The Requires

 

cache php bundle symfony phpfastcache