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

PSR-6 & Symfony Cache: fast by standards

Nicolas Grekas
September 16, 2016

PSR-6 & Symfony Cache: fast by standards

After several months of discussion, the PHP-FIG (PHP Framework Interop Group) published the PSR-6. Its goal is to enable interoperability between caching systems implementations - a mandatory aspect to improve performance in your applications. At this conference, we will see the benefits and limitations of PSR-6, we will discuss the various existing cache solutions (Doctrine, Stash, php-cache), and I will present the new Symfony 3.1 Cache component and its upcoming improvements in version 3.2.

Nicolas Grekas

September 16, 2016

More Decks by Nicolas Grekas

Other Decks in Technology


  1. “There are only two hard things in Computer Science: -

    cache invalidation - and naming things.” -- Phil Karlton
  2. #Symfony_Live @nicolasgrekas • A common interface for basic and intermediate-level

    caching needs. • Allow for multiple independent extensions without collision. PSR-6 Goals
  3. #Symfony_Live @nicolasgrekas • Architectural compatibility with all existing cache implementations.

    • Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals
  4. #Symfony_Live @nicolasgrekas • doctrine/cache 16.8M • sonata-project/cache 1.3M • zendframework/zend-cache

    1.1M • illuminate/cache 0.5M • tedivm/stash 0.4M PSR-6 Prior-art on Packagist
  5. #Symfony_Live @nicolasgrekas • Crippled with “Bylaws” • Not always representative

    • Strategic hijacking • Way too much noise/overhead • Mission is unclear PHP-FIG Weaknesses
  6. #Symfony_Live @nicolasgrekas • CacheItemInterface instances are not interoperable • Restricted

    characters for keys • false as error reporting • No atomicity/transactionality • Lazyness is unspecified PSR-6 Edge-cases
  7. #Symfony_Live @nicolasgrekas • See on Packagist https://packagist.org/providers/psr/cache-implementation • Stash PHP

    – stashphp.com • PHP Cache – php-cache.com • and … PSR-6 Implementations
  8. #Symfony_Live @nicolasgrekas • Be the most powerful PHP caching library

    • A strict PSR-6 implementation • Following Symfony’s quality processes* • Just the bare minimum to be fast by default * Thanks "cache/integration-tests"! Symfony Cache Goals in 3.1
  9. #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 Bench Symfony Cache
  10. #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 Bench Symfony Cache
  11. #Symfony_Live @nicolasgrekas Symfony Framework Concepts Front 1 - APCu Front

    2 - APCu Redis Pool 1: Code Annotations Pool 2: Validation Pool 3: SQL results Pool 4: API responses
  12. #Symfony_Live @nicolasgrekas • « cache.app » for model sourced items

    o Defaults to filesystem, change it to Redis • « cache.system » for code sourced items o Defaults to APCu+filesystem chain Symfony Framework Services
  13. #Symfony_Live @nicolasgrekas • Cache warming-up o Regeneration Before Expiration o

    Desynchronized Cache Misses o Stampede Protection Beyond PSR-6
  14. #Symfony_Live @nicolasgrekas • New adapter: PDO/DBAL, PHP array/file, Null •

    Tags based invalidation o $cache->invalidateTags($tags); • Hierarchical invalidation o $cache->withContext($contextChecksum); • cache:pool:clear command • Warm-up Validator, Serializer, etc. • Deprecate per components *CacheInterface Symfony 3.2
  15. #Symfony_Live @nicolasgrekas • Serve stale items while refreshing? • Desynchronized

    Cache Misses? • Add a profiler panel with hits/misses? • …add your ideas here Symfony 3.3?