Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony Cache: a premium recipe to fast apps

Nicolas Grekas
February 21, 2019

Symfony Cache: a premium recipe to fast apps

Introduced in version 3.1, the Symfony Cache component has 3 promises: performance, safety, and ease of use. Internally and by default, we are already using it out of the box for system caches. It started as a reference implementation of the PSR-6 standard. Along the years and by contributions from the community, it gained a battle-tested feature-set and adapters for many storages. But the next version, 4.2, is the bigger milestone. With some raw examples and benchmarks, let's review how to select the best backend for your needs, wire them in your apps, do tags-based invalidation, protect against cache stampede, etc. Caching might be the most efficient strategy to fast apps.

Nicolas Grekas

February 21, 2019
Tweet

More Decks by Nicolas Grekas

Other Decks in Technology

Transcript

  1. #Symfony_Live @nicolasgrekas • A common interface caching needs o With

    normalized error handling • Allow for multiple independent extensions PSR-6 Goals
  2. #Symfony_Live @nicolasgrekas • doctrine/cache 70M • symfony/cache 6.5M • zendframework/zend-cache

    4.5M • illuminate/cache 3.6M • tedivm/stash 1.4M Cache on Packagist
  3. #Symfony_Live @nicolasgrekas • A dual PSR-6 and PSR-16 implementation •

    With strict public API and error handling • With exclusive extra features • Tuned for performance • Following Symfony’s quality processes Symfony Cache
  4. #Symfony_Live @nicolasgrekas • Runtime Memory • Filesystem • PHP code

    – one file per item • PHP code – one file with all items • APCu Symfony Cache – Local backends
  5. #Symfony_Live @nicolasgrekas • Chain • Doctrine • Proxy • Null

    • SimpleCache • Traceable Symfony Cache – Special backends
  6. #Symfony_Live @nicolasgrekas Doctrine 834.863 items/ms PHP Cache 313.334 items/ms Stash

    PHP 55.346 items/ms Symfony 533.366 items/ms Symfony Cache – APCu Bench
  7. #Symfony_Live @nicolasgrekas Doctrine 705.001 items/ms PHP Cache 362.477 items/ms Stash

    PHP 153.803 items/ms Symfony 845.910 items/ms Symfony Cache – APCu Bench
  8. #Symfony_Live @nicolasgrekas • by expiration • by tags • by

    versioning Symfony Cache – Invalidation strategies
  9. #Symfony_Live @nicolasgrekas • cache.system = PHP7 array > APCu >

    files • Offline cache warm-ups for derived cache.validator/serializer/annotations • Fine tuned flex recipes for Doctrine Note: APCu warmup & reset handled properly Best wiring by default
  10. #Symfony_Live @nicolasgrekas • Cache\{CacheInterface, TagAwareInterface} • Translation\TranslatorInterface • Service\{ResetInterface, ServiceLocatorTrait,

    ServiceSubscriberInterface, ServiceSubscriberTrait} • v1.0 released at the end of November • README https://github.com/symfony/contracts Symfony\Contracts\
  11. #Symfony_Live @nicolasgrekas • Offline recomputation (DI+Messenger+Cache integration) • 1RTT Redis

    tag invalidation (joint effort with eZ Platform, they use it the most) What’s next?