1. Go to this page and download the library: Download snicholson/slimfilecache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
snicholson / slimfilecache example snippets
composer
//Start up a new slim app
$slim = new App($container);
// Add file cache middleware
$cache = new \SNicholson\SlimFileCache\Cache($slim);
$slim->add($cache);
//Start up a new slim app
$slim = new App($container);
// Add file cache middleware
$cache = new \SNicholson\SlimFileCache\Cache($slim, 'relate/path/to/cache/directory');
$slim->add($cache);
//Configure the "foo" route and cache the output
$slim->get(
'/foo',
function(\Slim\Http\Request $request, \Slim\Http\Response $response, $args) use ($cache) {
$response = 'foo response string';
$cache->add('/foo', $response);
return $response;
}
);
//Run the slim app (like normal)
$slim->run();
//Place the global cache afterwards, the next request at this route will be cached
$cache->add($slim->request->getUri()->getPath(), $slim->response->getBody()->__toString());
$cache = new \SNicholson\SlimFileCache\Cache($slim)
//Flush removes all entries
$cache->flush();
//Remove a single cache entry
$cache->remove('/foo');
//Get returns what is stored in the cache
$response = $cache->get('/foo');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.