UnionOfRAD/lithium — pull request #1070 by davidpersson (2014-02-22 22:17:16+00:00)
Title: Implementing and decoupling advanced cache key generation; BC break.

Repurposing `Cache::key()`. It now deals with advanced cache key generation
and also makes keys safe to use with given adapter configuration.

BC break: Method signature of `Cache::key()` changed. This method
was probably used seldom because of its very limited featureset.

BC break of undocumented feature: key generator functions
cannot be passed to `Cache::{read,write,delete,increment,decrement}()`
anymore. See explanation below.

- Method signature of `Cache::key()` changed. The first
parameter is now - as in other cache methods - the name
of the cache configuration to use.

```
Cache::key('post', $data); // old
Cache::key('default', 'post', $data); // new
```

- Decoupling cache key generation.

Advanced key generation has been moved out of
`Cache::{read,write,delete,increment,decrement}()`. Key generator
functions may not be passed to these methods anymore. Instead generate
the key beforehand using the new `Cache::key()`.

Key generator functions for read and delete needed to be implemented
in a different way then those for i.e. write as data could not be
passed to them in any case.

```
$data = array('id' => 23);

// old: removed
Cache::write('default', function($data) { // ... }, $data);

// new: 2 step process
$key = Cache::key('default', function($data) { // ... }, $data);
Cache::write('default', $key, $data);
```

- The method can now be used to generate safe cache keys.

- The method can now be used to suffix cache keys with
hashes of data.

- Adding `keys()` method for adapters.

- Adding tests.

- Adding documentation.