RWOverdijk/AssetManager — pull request #128 by wshafer (2014-04-14 02:23:54+00:00)
Title: Refactor asset cache Manager + Zend Cache Adaptor

Based on Ocramius review of PR #127, I have taken a stab at refactoring the Asset Cache Manger to pull services from the SM where possible.

The provider factory now accepts 4 ways to configure the cache. Callback, A Zend Service, Class name, and a BC mapper for things like "APC"

Possible way's to configure the caches are as follows:

```php
return array(
'asset_manager' => array(
'caching' => array(
//Callback method for BC
'callback_example.tmp' => array(
'cache' => function() {
return new myCache();
},
),
// Zend Service Key
'zend_service_example.tmp' => array(
'cache' => 'myZf2ServiceManagerService',
),

// Classname
'class_name_example.tmp' => array(
'cache' => 'AssetManager\\Cache\\FileManager',
'options' => array(
'dir' => 'someDir',
),
),

// BC Definitions
'bc_example.tmp' => array(
'cache' => 'Apc',
),
),
),
);
```

Also attached is a Zend Cache Adaptor for Assetic. In order for this to work the adapter needs the cache injected. As such I have only set this up to be used via the service manager.

To configure this adapter here is one possible solution:

File: MyApplication/Module.php
```php
array(
'AssetManagerCache' => function ($serviceLocator) {
$zfCacheConfig = array(
'adapter' => array(
'name' => 'Memcached',
'options' => array(
'servers' => array(
array('localhost','11211'),
),
'namespace' => 'zfcache',
),
),
'plugins' => array(),
);

$zendCacheStorage = StorageFactory::factory($zfCacheConfig);

return new ZendCacheAdaptor($zendCacheStorage);
},
),
);
}
}
```

And my config/autoload/local.php config would look like:
```php
array(
'caching' => array(
'default' => array(
'cache' => 'AssetManagerCache'
),
),
),
);
```