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

Caching with PSRs at Dutch PHP Conference

Caching with PSRs at Dutch PHP Conference

In this talk you will learn what PSR-6 and PSR-16 are, why they are designed like they are, what the differences are, and how to use them. From the provided interfaces, the virtual package on Packagist.org, to the implementations available. Everything will be explained for both beginners and more experienced developers. We will dive into implementations, cache stampede protection, all using libraries we can find on Packagist.org. We will also show how to start using it today in our current applications by using adapters. The entire talk will be accompanied with code samples and live demos, showing both working and failing caching systems.

Hannes Van De Vreken

June 30, 2017
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Technology

Transcript

  1. !

  2. WHAT IS CACHING - EXAMPLES • HTTP Request • Slow

    DB call • Process image/zip/…
  3. APPLICATION CACHING IN 2015 Frameworks & cache libs have their

    own: - set of supported caching back-ends - interface to allow custom implementations
  4. APPLICATION CACHING IN 2015 Framework X cache Framework Y cache

    Package W cache Cache package Z Adapter W->X Adapter W->Y Adapter W->Z Adapter Y->Z
  5. APPLICATION CACHING IN 2015 If no adapter available - Write

    your own - Store in different cache stores
  6. INTRODUCING PSR-6 Don’t instantiate your own Items. $item = $pool->getItem(‘key’)

    ->set($value) ->expiresAfter(3600); $pool->save($item);
  7. INTRODUCING PSR-6 Cache features: - Stampede protection - Taggable cache

    $item->addTags(['cat-1']); $pool->clearTags(['cat-1']);
  8. INTRODUCING PSR-6 Cache features: - Stampede protection - Taggable cache

    - Hierarchical cache $pool->delete('tree/*'); // {}()/\@:
  9. START USING IT class PoolIntegrationTest extends CachePoolTest { public function

    createCachePool() { return new CustomCachePool(); } }
  10. START USING IT - UPGRADE Start using PSR-6 enabled libraries

    with adapters for current FW’s implementation.
  11. // Returns null when not available. // Returns null when

    you set it. $cache->set($key, null); $value = $cache->get($key); INTRODUCING PSR-16