SlideShare a Scribd company logo
1 of 16
Download to read offline
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
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 PsrCacheCacheItemPoolInterface;


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 2017

releases (earliest December)
๏Interested in talking or

sponsoring Symfony

meetups? 

=> Contact organizers on the

Symfony 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 EXPRESSION
const 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

More Related Content

More from André Rømcke

eZ Publish 5, Re architecture, pitfalls and opportunities
eZ Publish 5, Re architecture, pitfalls and opportunitieseZ Publish 5, Re architecture, pitfalls and opportunities
eZ Publish 5, Re architecture, pitfalls and opportunities
André Rømcke
 

More from André Rømcke (8)

SymfonyCon 2019: Head first into Symfony Cache, Redis & Redis Cluster
SymfonyCon 2019:   Head first into Symfony Cache, Redis & Redis ClusterSymfonyCon 2019:   Head first into Symfony Cache, Redis & Redis Cluster
SymfonyCon 2019: Head first into Symfony Cache, Redis & Redis Cluster
 
SfDay 2019: Head first into Symfony Cache, Redis & Redis Cluster
SfDay 2019: Head first into Symfony Cache, Redis & Redis ClusterSfDay 2019: Head first into Symfony Cache, Redis & Redis Cluster
SfDay 2019: Head first into Symfony Cache, Redis & Redis Cluster
 
Symfony live London 2018 - Take your http caching to the next level with xke...
Symfony live London 2018 -  Take your http caching to the next level with xke...Symfony live London 2018 -  Take your http caching to the next level with xke...
Symfony live London 2018 - Take your http caching to the next level with xke...
 
Look Towards 2.0 and Beyond - eZ Conference 2016
Look Towards 2.0 and Beyond -   eZ Conference 2016Look Towards 2.0 and Beyond -   eZ Conference 2016
Look Towards 2.0 and Beyond - eZ Conference 2016
 
Dockerize your Symfony application - Symfony Live NYC 2014
Dockerize your Symfony application - Symfony Live NYC 2014Dockerize your Symfony application - Symfony Live NYC 2014
Dockerize your Symfony application - Symfony Live NYC 2014
 
PhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cachePhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cache
 
eZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureeZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & Architecture
 
eZ Publish 5, Re architecture, pitfalls and opportunities
eZ Publish 5, Re architecture, pitfalls and opportunitieseZ Publish 5, Re architecture, pitfalls and opportunities
eZ Publish 5, Re architecture, pitfalls and opportunities
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 

Symfony meetup: PSR-6 & Symfony 3.1 Cache Component

  • 1. 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
  • 2. 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
  • 3. 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/
  • 4. www.ez.noez.no PSR-6: Example namespace PsrCacheCacheItemPoolInterface; 
 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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.
  • 11. 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.
  • 12. 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 2017
 releases (earliest December) ๏Interested in talking or
 sponsoring Symfony
 meetups? 
 => Contact organizers on the
 Symfony meetup.com page!
  • 13. www.ez.noez.no Bonus #1: Incoming Symfony Cache Adapter ๏OpCache (ongoing PR right now building on work done in Composer v1.1/v2)
  • 14. www.ez.noez.no Bonus #2: Autoload performance in Composer.next
  • 15. ez.no Bonus #3: Plain Array? NORMAL DYNAMIC ARRAY $array = [
 $vendorDir.’/symfony/symfony',
 $vendorDir.’/ezsystems/ezpublish-kernel'
 ]; ARRAY USING CONSTANT EXPRESSION const 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