I was searching for a way to use illuminate\cache with slim and did not found anything for current the version, only old posts for slim2 and illuminate\cache 4.3
I came up with this solution by updating old examples, and while its working i would like to know if its the right way or if there’s a better way to do it.
// Cache.
$container[‘cache’] = function ($c) {
$settings = $c->get(‘settings’);
$ic = new \Illuminate\Container\Container;
$ic['config'] = $settings['cache']; $ic['files'] = new \Illuminate\Filesystem\Filesystem;
$cacheManager = new \Illuminate\Cache\CacheManager($ic);
$cache = $cacheManager->driver();
return $cache;
};
And settings:
//Cache settings. 'cache' => [ 'cache.default' => 'file', 'cache.stores.file' => [ 'driver' => 'file', 'path' => BASE_PATH . '/cache' ] ],
Usage:
$app->get('/cache', function ($request, $response, $args) { $this->cache->put('foo', 'bar', 5); dd($this->cache->get('foo')); });