tedivm/Stash — Issue #23: More complex handlers
Author: lstrojny
Created: 2012-02-23 21:42:29+00:00
State: open

While working on Ephemeral Handler I more and more loved the idea to make handlers more capable to achieve more complex caching strategies and on the other hand to separate concers in `Stash\Cache` more cleanly. These are the use cases I have in mind:

- Store in Memcache only (currently achievable by disabling memory storage in `Stash\Cache` and using `Memcache` handler)
- Size bases balancing: Store small entries in APC, large ones in Memcache (currently not possible)
- Overflow based balancing: store everything in APC but overflow to Memcache (currently no possble)
- Any combination of those use cases

Architecture overview:

- We split handlers into three layers: invocation strategies (the "what is invoked"), handlers (interacts with the caching store) and drivers (abstracts client differences for `Memcache` vs. `Memcached`, `Predis` vs. `PHP Redis`)
- A `CompositeHandler` uses an `InvocationStrategy` to call instances of `HandlerInterface`. `InvocationStrategy` works on a `HandlerCollection` and decides what instance of `HandlerInterface` needs to be called and calls it
- A `Handler` *may* use a `Driver` to do it’s work

Here’s some pseudo code:

```php