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

PSR-6 & Symfony Cache: fast by standards

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 Symfony 3.1 Cache component and its latest improvements in version 3.2.

Nicolas Grekas

December 01, 2016

Transcript

40 slides
  1. #SymfonyCon @nicolasgrekas • A common interface for basic and intermediate-level

    caching needs. • Allow for multiple independent extensions without collision. PSR-6 Goals
  2. #SymfonyCon @nicolasgrekas • Compatibility with all existing cache implementations. •

    Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals
  3. #SymfonyCon @nicolasgrekas • doctrine/cache 26.3M • sonata-project/cache 2.0M • zendframework/zend-cache

    1.9M • illuminate/cache 1.0M • tedivm/stash 0.6M PSR-6 Prior-art on Packagist
  4. #SymfonyCon @nicolasgrekas • getItem is the only standardized item factory

    • Keys cannot use reserved chars • false is returned on backend-errors • Atomicity/transactions/laziness is unspecified • Cache items are not interoperable PSR-6 Edge-cases
  5. #SymfonyCon @nicolasgrekas • See on Packagist https://packagist.org/providers/psr/cache-implementation • Stash PHP

    – stashphp.com • PHP Cache – php-cache.com • and … PSR-6 Implementations
  6. #SymfonyCon @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 * thank you Tobias for "cache/integration-tests“! Symfony Cache Goals in 3.1
  7. #SymfonyCon @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter • RedisAdapter

    • …it’s up to you to add more Base Symfony Cache Adapters
  8. #SymfonyCon @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 - APCu
  9. #SymfonyCon @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 - APCu
  10. #SymfonyCon @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 Existing Cache Pool Services
  11. #SymfonyCon @nicolasgrekas • PdoAdapter works for Doctrine DBAL • PhpArrayAdapter

    one big PHP 7 static array in shm • PhpFileAdapter many small PHP 7 static array in shm • NullAdapter pro-tip: item factory for any Symfony adapters New in Symfony 3.2
  12. #SymfonyCon @nicolasgrekas • cache.system = PHP7 array > APCu >

    files • Offline cache warm-ups for derived cache.validator/serializer/annotations Note: APCu warmup & reset handled properly New in Symfony 3.2
  13. #SymfonyCon @nicolasgrekas • Serve stale items while refreshing? • Desynchronized

    Cache Misses? • Add a profiler panel with cache stats? • PSR-16 SimpleCache? • …add your ideas here Symfony 3.3?

More Decks by Nicolas Grekas

Other Decks in Technology