2017 © Pedro Peláez
 

library cache

Toast PSR-6-compatible cache module

image

toast/cache

Toast PSR-6-compatible cache module

  • Tuesday, May 2, 2017
  • by monomelodies
  • Repository
  • 1 Watchers
  • 0 Stars
  • 47 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

Cache

Caching module for the Toast test framework, (*1)

Why would a testing framework need caching, you might ask? Well, sometimes a particular piece of code does something that isn't that easily otherwise checked (e.g. sending a mail), or if you write acceptance tests you might need a way to check if the external server did something correctly. The module is called cache because it's fully PSR-16 compliant, but you really should think of it more as a shared pool you can access for temporary storage while running a test scenario., (*2)

Installation

composer require toast/cache

Manual

  • Download or clone the repository somewhere;
  • Register /path/to/cache/src for the Toast\Cache namespace in your autoloader.

Initialising a cache pool

Create a new Toast\Cache\Cache object like so:, (*3)

<?php

use Toast\Cache\Cache;

$cache = new Cache('/path/to/storage');

Alternatively, the cache can also be accessed as a singleton:, (*4)

<?php

use Toast\Cache\Cache;

$pool = Cache::getInstance('/path/to/storage');

This is escpecially handy when sharing throughout tests; although as long as the path stays the same, the cache will reload existing data regardless., (*5)

Note that you can instantiate multiple, sandboxed caches using different paths., (*6)

Storing and retrieving items in the cache

Anything serializable can be stored in the cache using set or setMultiple:, (*7)

<?php

use Toast\Cache\Cache;

$someVariable = 'I need to be cached!';

$pool = Cache::getInstance('/path/to/storage');
$pool->save('some-unique-key', $someVariable);
$pool->has('some-unique-key'); // true

// ...somewhere else in your code...

$item = Cache::getInstance('/path/to/storage')->get('some-unique-key');
echo $item; // string "I need to be cached!"

TTLs

PSR-16 allows cached items to define an optional Time To Live (TTL). Since this does not make any sense in the context of unit testing, the parameter is ignored., (*8)

The Versions

02/05 2017

dev-master

9999999-dev

Toast PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

02/05 2017

0.2.2

0.2.2.0

Toast PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

02/05 2017

0.2.1

0.2.1.0

Toast PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

02/05 2017

0.2.0

0.2.0.0

Toast PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

05/11 2016

0.1.4

0.1.4.0

Gentry PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

28/10 2016

0.1.3

0.1.3.0

Gentry PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

28/10 2016

0.1.2

0.1.2.0

Gentry PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

10/07 2016

0.1.1

0.1.1.0

Gentry PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst

10/07 2016

0.1.0

0.1.0.0

Gentry PSR-6-compatible cache module

  Sources   Download

MIT

The Requires

 

by Marijn Ophorst