<?php require_once __DIR__ . '/vendor/autoload.php'; use Cachet\CacheEngine\RedisCacheEngine; use Cachet\Controller\GlobalCacheController; use Cachet\Controller\KeyCacheController; $router = new Yari\Router(); /** * Once requested, redisProvider will create a connection to redis and return it. */ $redisProvider = function () { $redis = new RedisCacheEngine(); $redis->connect('192.168.112.111'); $redis->select(1); return $redis; }; $router->addController('global_cache', function () use($redisProvider) { $redis = $redisProvider(); return new GlobalCacheController($redis); }); $router->addController('key_cache', function () use($redisProvider) { $redis = $redisProvider(); return new KeyCacheController($redis); }); $router->get('/cache', 'global_cache:getAllKeyValuePairs'); $router->post('/cache', 'global_cache:createNewKeyValuePair'); $router->delete('/cache', 'global_cache:deleteAllKeyValuePairs'); $router->get('/stats', 'global_cache:getStats'); $router->get('/cache/*key', 'key_cache:getValue'); $router->put('/cache/*key', 'key_cache:update'); $router->delete('/cache/*key', 'key_cache:delete');