Caching with PSR-6 Laravel Barcelona @laravelbcn @ hannesvdvreken - - PowerPoint PPT Presentation

caching with psr 6
SMART_READER_LITE
LIVE PREVIEW

Caching with PSR-6 Laravel Barcelona @laravelbcn @ hannesvdvreken - - PowerPoint PPT Presentation

Caching with PSR-6 Laravel Barcelona @laravelbcn @ hannesvdvreken Hi, my name is Hannes. made with love.be 20 PSR-6 Caching in PHP anno 2016 1. Intro 2. Caching in 2015 3. Hello PSR-6 4. Practical


slide-1
SLIDE 1

Caching with PSR-6

Laravel Barcelona  @hannesvdvreken @laravelbcn

slide-2
SLIDE 2

Hi, my name is Hannes.

slide-3
SLIDE 3

🏄💼

slide-4
SLIDE 4

madewithlove.be

20 × 😎



slide-5
SLIDE 5
slide-6
SLIDE 6

PSR-6

Caching in PHP anno 2016

slide-7
SLIDE 7
  • 1. Intro
  • 2. Caching in 2015
  • 3. Hello PSR-6
  • 4. Practical
slide-8
SLIDE 8
  • 1. Intro

what is caching?

slide-9
SLIDE 9

WHAT IS CACHING

Speeding up your app

slide-10
SLIDE 10

WHAT IS CACHING

  • 1. Execute slow task

2.Remember result 3.Use stored value

slide-11
SLIDE 11

WHAT IS CACHING

Should not cause app failure

slide-12
SLIDE 12

WHAT IS CACHING - EXAMPLES

  • HTTP Request
  • Slow DB call
  • Process image/zip/…
slide-13
SLIDE 13

WHAT IS CACHING

Should not cause app failure

slide-14
SLIDE 14

WHAT IS CACHING

geocode IP check cache store result check cache

slide-15
SLIDE 15

WHAT IS CACHING

Should not cause app failure

slide-16
SLIDE 16

WHAT IS CACHING

At different layers:

User-Agent Webserver (Varnish/Nginx) Application Opcache

slide-17
SLIDE 17

WHAT IS CACHING

Should not cause app failure

slide-18
SLIDE 18
  • 2. Caching in 2015

the state of caching (pre PSR-6)

slide-19
SLIDE 19

APPLICATION CACHING IN 2015

  • 1. Libraries do it

2.Frameworks do it 3.Cache libs do it

slide-20
SLIDE 20

APPLICATION CACHING IN 2015

Frameworks & cache libs have their own:

  • interfaces
  • support for caching systems
slide-21
SLIDE 21

APPLICATION CACHING IN 2015

Adapters everywhere!

slide-22
SLIDE 22

APPLICATION CACHING IN 2015

If no adapter available

  • Write your own
  • Store in different cache stores
slide-23
SLIDE 23
  • 3. Hello PSR-6

what does that mean?

slide-24
SLIDE 24

INTRODUCING PSR-6

Finalised & accepted in December 2015

slide-25
SLIDE 25

INTRODUCING PSR-6

Repository - Entity

slide-26
SLIDE 26

INTRODUCING PSR-6

use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemInterface; $item = $pool->getItem($key); $item->getKey();

slide-27
SLIDE 27

INTRODUCING PSR-6

Lemme see that code

slide-28
SLIDE 28

INTRODUCING PSR-6

Don’t instantiate your own Items.

$item = $pool->getItem(‘key’)

  • >set($value)
  • >expiresAfter(3600);

$pool->save($item);

slide-29
SLIDE 29

INTRODUCING PSR-6

Item is an entity, it’s not immutable, but the Key is

slide-30
SLIDE 30

INTRODUCING PSR-6

CacheItemInterface has no getExpiresAt

slide-31
SLIDE 31

INTRODUCING PSR-6

Pool has support for multi-actions $pool->getItems($keys); $pool->saveDeferred($item); $pool->commit();

slide-32
SLIDE 32

INTRODUCING PSR-6

Repository - Entity model allows extensions

slide-33
SLIDE 33

INTRODUCING PSR-6

Cache features:

  • Stampede protection:

Parallel incoming requests executing long process to update cache value

slide-34
SLIDE 34

INTRODUCING PSR-6

Cache features:

  • Stampede protection
  • Taggable cache

$item->addTags(['cat-1']); $pool->clearTags(['cat-1']);

slide-35
SLIDE 35

INTRODUCING PSR-6

Cache features:

  • Stampede protection
  • Taggable cache
  • Hierarchical cache

$pool->delete('tree/*');

slide-36
SLIDE 36
  • 4. Practical

who uses it, and how can I use it?

slide-37
SLIDE 37
slide-38
SLIDE 38
slide-39
SLIDE 39

START USING IT

Integration tests for implementations: cache/integration-tests

slide-40
SLIDE 40
slide-41
SLIDE 41

START USING IT

class PoolIntegrationTest extends CachePoolTest { public function createCachePool() { return new CachePool(); } }

slide-42
SLIDE 42

START USING IT - UPGRADE

Upgrade paths

slide-43
SLIDE 43

START USING IT - UPGRADE

Libraries

slide-44
SLIDE 44

START USING IT - UPGRADE

Libraries (next major versions) have a PSR-6 caching decorator

slide-45
SLIDE 45
slide-46
SLIDE 46

START USING IT - UPGRADE

Frameworks

slide-47
SLIDE 47

START USING IT - UPGRADE

Start using PSR-6 enabled libraries with adapters for current FW’s implementation.

slide-48
SLIDE 48

START USING IT - UPGRADE

Example: Laravel PSR-6 bridge

slide-49
SLIDE 49
slide-50
SLIDE 50
  • 1. Intro
  • 2. Caching in 2015
  • 3. Hello PSR-6
  • 4. Practical

RECAP

slide-51
SLIDE 51
slide-52
SLIDE 52

Hello PSR-16

slide-53
SLIDE 53

Thank you!

https:/ /joind.in/talk/xxxxx @hannesvdvreken @laravelbcn

slide-54
SLIDE 54

Questions & discussions

@hannesvdvreken @laravelbcn