Caching with PSRs at PHP Srbija

Caching with PSRs at PHP Srbija

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.

39eb3f3d313b13f05534e496285040b8?s=128

Hannes Van De Vreken

May 27, 2018
Tweet

Transcript

  1. 9.

    WHAT IS CACHING - EXAMPLES • HTTP Request • Slow

    DB call • Process image/zip/…
  2. 18.

    APPLICATION CACHING IN 2015 Frameworks & cache libs have their

    own: - set of supported caching back- ends - interface to allow custom implementations
  3. 20.

    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
  4. 21.

    APPLICATION CACHING IN 2015 If no adapter available - Write

    your own - Store in different cache stores
 (ops will not love you for that)
  5. 27.

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

    ->set($value) ->expiresAfter(3600); $pool->save($item);
  6. 43.

    INTRODUCING PSR-6 Cache features: - Stampede protection - Taggable cache

    $item->setTags(['cat-1']); $pool->invalidateTags(['cat-1']);
  7. 44.

    INTRODUCING PSR-6 Cache features: - Stampede protection - Taggable cache

    - Hierarchical cache cache/hierarchical-cache
  8. 45.

    INTRODUCING PSR-6 Cache features: - Stampede protection - Taggable cache

    - Hierarchical cache $pool->hasItem('|users|4711|followers'); // true $pool->delete(‘|users|4711'); $pool->hasItem('|users|4711|followers'); // false
  9. 47.
  10. 48.
  11. 49.
  12. 51.
  13. 52.

    START USING IT class PoolIntegrationTest extends CachePoolTest { public function

    createCachePool() { return new CustomCachePool(); } }
  14. 58.

    START USING IT - UPGRADE Start using PSR-6 enabled libraries

    with adapters for current FW’s implementation.
  15. 60.
  16. 63.
  17. 68.

    // Returns null when not available. // Returns null when

    you set it to null. $cache->set($key, null); $value = $cache->get($key); INTRODUCING PSR-16
  18. 76.
  19. 77.
  20. 80.
  21. 81.
  22. 82.