Slide 1

Slide 1 text

PSR-6 & Symfony Cache fast by standards #SymfonyCon @nicolasgrekas joind.in

Slide 2

Slide 2 text

@nicolasgrekas # SymfonyCon

Slide 3

Slide 3 text

#SymfonyCon @nicolasgrekas

Slide 4

Slide 4 text

#SymfonyCon @nicolasgrekas

Slide 5

Slide 5 text

#SymfonyCon @nicolasgrekas

Slide 6

Slide 6 text

PHP-FIG Strength Standards! And wish the best to FIG 3.0

Slide 7

Slide 7 text

PSR-6 Caching Interface Draft: Sept. 2013 Final: Dec. 2015

Slide 8

Slide 8 text

#SymfonyCon @nicolasgrekas • A common interface for basic and intermediate-level caching needs. • Allow for multiple independent extensions without collision. PSR-6 Goals

Slide 9

Slide 9 text

#SymfonyCon @nicolasgrekas • Compatibility with all existing cache implementations. • Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals

Slide 10

Slide 10 text

#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

Slide 11

Slide 11 text

#SymfonyCon @nicolasgrekas PSR-6 CacheItemInterface

Slide 12

Slide 12 text

#SymfonyCon @nicolasgrekas PSR-6 CacheItemPoolInterface

Slide 13

Slide 13 text

#SymfonyCon @nicolasgrekas PSR-6 Example #1

Slide 14

Slide 14 text

#SymfonyCon @nicolasgrekas PSR-6 Example #2

Slide 15

Slide 15 text

#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

Slide 16

Slide 16 text

#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

Slide 17

Slide 17 text

Symfony Cache 3.1 What else?

Slide 18

Slide 18 text

#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

Slide 19

Slide 19 text

#SymfonyCon @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter • RedisAdapter • …it’s up to you to add more Base Symfony Cache Adapters

Slide 20

Slide 20 text

#SymfonyCon @nicolasgrekas • AbstractAdapter • ChainAdapter • DoctrineAdapter • ProxyAdapter • + DoctrineProvider Special Symfony Cache Adapters

Slide 21

Slide 21 text

#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

Slide 22

Slide 22 text

#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

Slide 23

Slide 23 text

#SymfonyCon @nicolasgrekas Doctrine 34.061 items/ms Symfony 478.910 items/ms Bench Symfony Cache - Redis

Slide 24

Slide 24 text

Symfony Framework Wiring

Slide 25

Slide 25 text

$container->get('cache.app') or @cache.app in yml

Slide 26

Slide 26 text

#SymfonyCon @nicolasgrekas framework: cache: pools: my_app.cache.geodata => @my_app.cache.geodata in services.yml app/config/config.yml

Slide 27

Slide 27 text

#SymfonyCon @nicolasgrekas framework: cache: pools: my_app.cache.geodata public: true => $container->get('my_app.cache.geodata‘) app/config/config.yml

Slide 28

Slide 28 text

#SymfonyCon @nicolasgrekas framework: cache: pools: my_app.cache.geodata adapter: cache.adapter.redis app/config/config_prod.yml

Slide 29

Slide 29 text

#SymfonyCon @nicolasgrekas framework: cache: app: cache.adapter.redis app/config/config_prod.yml

Slide 30

Slide 30 text

#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

Slide 31

Slide 31 text

#SymfonyCon @nicolasgrekas services: geocoder.doctrine_cache: class: Symfony\Component\Cache\DoctrineProvider arguments: - '@my_app.cache.geodata' app/config/services.yml

Slide 32

Slide 32 text

Symfony Cache 3.2 PSR-6 and beyond

Slide 33

Slide 33 text

#SymfonyCon @nicolasgrekas ./bin/console cache:pool:clear my_app.geocoder.cache New in Symfony 3.2

Slide 34

Slide 34 text

#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

Slide 35

Slide 35 text

#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

Slide 36

Slide 36 text

#SymfonyCon @nicolasgrekas • Tags based invalidation New in Symfony 3.2

Slide 37

Slide 37 text

#SymfonyCon @nicolasgrekas Tags based invalidation

Slide 38

Slide 38 text

#SymfonyCon @nicolasgrekas Tags based invalidation

Slide 39

Slide 39 text

#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?

Slide 40

Slide 40 text

joind.in #SymfonyCon @nicolasgrekas Merci