symfony meetup: psr-6 & symfony 3.1 cache component

16
SYMFONY PHP OSLO MEETUP New in upcoming Symfony 3.1: CACHE COMPONET “PSR-6 Cache, Symfony Cache component, and beyond” André Rømcke - VP Engineering @ezsystems Apr. 20th 2016 - Oslo - Norway Symfony Meetup

Upload: andre-romcke

Post on 17-Feb-2017

1.785 views

Category:

Technology


2 download

TRANSCRIPT

SYMFONY PHP OSLO MEETUPNew in upcoming Symfony 3.1: CACHE COMPONET “PSR-6 Cache, Symfony Cache component, and beyond”

André Rømcke - VP Engineering @ezsystems Apr. 20th 2016 - Oslo - Norway Symfony Meetup

www.ez.noez.no

Me

๏André Rømcke @andrerom

๏VP Engineering at eZ Systems AS, eZ is:

Symfony Full stack user & active ecosystem member since 2012

Partner with Sensio Labs (and Blackfire)

Open Source CMS for more then 15 years with deep needs for intelligent caching

๏ PHP-FIG voting member

Currently user of Stash Cache, project that originally initiated PSR-6

Been at times participating in discussions around PSR-6 and Symfony Cache

www.ez.noez.no

PSR-6?

๏ First proposed in Dec 14, 2011, final version approved Dec 8, 2015

๏Been true several iterations, polls among PHP users/library-providers, ..

๏Will be expanded in the future with additional features as implementations evolves

๏ Some known implementations:

๏ Stash

๏ PHP-Cache

๏ Symfony

๏ ..and many others

๏ http://www.php-fig.org/psr/psr-6/

www.ez.noez.no

PSR-6: Example

namespace Psr\Cache\CacheItemPoolInterface;

function getWidgetList(CacheItemPoolInterface $pool){ $item = $pool->getItem('widget_list');// or getItems($array) to load several cache items

if (!$item->isHit()) {

$item->set($this->computeExpensiveWidgetList());

$pool->save($item);// or saveDeferred() if it can be saved in batch by end of request

}

return $item->get(); }

No need to type hint against Symfony with this

www.ez.noez.no

Symfony Cache?

www.ez.noez.no

Symfony Cache Component

๏ PSR-6 Compliant cache component

๏Aims to be fast, made by Blackfire CTO: Nicolas Grekas

๏ Provides several built in cache adapters by default

๏ Is progressively being used in several places in Symfony Framework, right now:

๏ PropertyInfo

๏ Serializer

๏Validator

As per April 2016

See bonus slides at the end

www.ez.noez.no

Symfony Cache Adapters

๏APCu (per proces cache)

๏Array (in memory per request, mainly for testing)

๏Chain (chain several adapters after each-other)

๏Doctrine

๏ FileSystem

๏ Proxy (To reuse other PSR-6 implementations)

๏Redis

๏ and more being added as we speak..

As per April 2016

See next slide

www.ez.noez.no

Doctrine Cache Providers

๏APC & APCu (per proces cache)

๏Array (in memory per request, mainly for testing)

๏Chain (chain several providers after each-other)

๏Couchbase

๏ File & FileSystem & PhpFile

๏Memcache & Memcached

๏MongoDB

๏Redis & Predis

๏Riak

๏SQLite3

๏WinCache

๏Cache

๏ZendCache

As per April 2016

www.ez.noez.no

Cache Libs Comparisons: Features

Stash Doctrine Symfony**

Multi GET X* V V

Hierarchical V X X

Versioning X V X

Namespacing V V V

Tagging X X X

PSR-6 V X V* Not implemented, interface has existed for long time. ** As of Symfony 3.1

www.ez.noez.no

Cache Libs Comparisons: Backend lookups

Stash* Doctrine** Symfony***

article-42 2 2 1

content/item-42 3 2 1

content/item-42 & content/item-33 5 2 1

*** W/ native adapters, not Doctrine.* memcached/redis, to compute keys for hierarchical cache. ** With versioning.

Round trips done to backend cache system for a given cache item(s) lookup, esp. important if high latency.

www.ez.noez.no

Next steps for eZ perspective

๏Currently rely on Hierarchical caching to handle cache clearing on related items

๏ Lets us clear cache content/55/*, and it will clear all objects we have there

๏However limited when we need to clear cache on tree/batch operations in the CMS

๏ eg deleting News/ will in some cases cause all content/* cache being cleared

๏Aiming to use Cache Tagging for this instead in data cache (and HTTPCache*)

๏ Example: content-55-version-44 cache item would have tags like:

• content-55

• location-33

• content-type-1 aka Folder • [ location-path-2, location-path-13, location-path-33 ]

• Will allow us to clear relevant cache much more precisely without cache dog piling

* We already support single tag across Varnish and Symfony Proxy, aim is to support multi tag for all.

www.ez.noez.no

Practical Info

๏Symfony 3.1 is coming end of May 2016

๏eZ working with others to add Tagging support

๏Either in Symfony or in Symfony Community

๏We aim to move to Symfony 3.x for our 2017releases (earliest December)

๏ Interested in talking or sponsoring Symfonymeetups? => Contact organizers on theSymfony meetup.com page!

www.ez.noez.no

Bonus #1: Incoming Symfony Cache Adapter

๏OpCache (ongoing PR right now building on work done in Composer v1.1/v2)

www.ez.noez.no

Bonus #2: Autoload performance in Composer.next

ez.no

Bonus #3: Plain Array?

NORMAL DYNAMIC ARRAY$array = [ $vendorDir.’/symfony/symfony', $vendorDir.’/ezsystems/ezpublish-kernel'];

ARRAY USING CONSTANT EXPRESSIONconst ARR = [ __DIR__.’/symfony/symfony', __DIR__.’/ezsystems/ezpublish-kernel'];

DIFFERENCE?As of PHP 5.6 with Constant Expressions, opcache I can avoid having to load the array and execute it on each request by using a constant, as it can be reuse directly from SHM (Shared Memory Cache). On large (Symfony) installs when using composer “dump-autoload” this class map can be several megabytes which is why this can have a big impact.Further reading: http://blog.blackfire.io/speeding-up-autoloading-on-php-5-6-7-0-for-everyone.html

Fin

ez.no