1. Go to this page and download the library: Download silentbyte/litecache 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/ */
silentbyte / litecache example snippets
$cache = new \SilentByte\LiteCache\LiteCache();
$config = $cache->get('config');
if ($config === null) {
$config = json_decode(file_get_contents('config.json'), true);
$cache->set('config', $config);
}
var_dump($config);
// Create the cache object with a customized configuration.
$cache = new \SilentByte\LiteCache\LiteCache([
// Specify the caching directory.
'directory' => '.litecache',
// Make cached objects expire after 10 minutes.
'ttl' => '10 minutes'
]);
// Issue a Github API request and cache it under the specified name ('git-request').
// Subsequent calls to $cache->cache() will be fetched from cache;
// after expiration, a new request will be issued.
$response = $cache->cache('git-request', function () {
$ch = curl_init('https://api.github.com/users/SilentByte');
curl_setopt($ch, CURLOPT_USERAGENT, 'SilentByte/litecache');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return json_decode(curl_exec($ch));
});
echo "Name: ", $response->login, "\n",
"Website: ", $response->blog, "\n",
"Update: ", $response->updated_at, "\n";
use SilentByte\LiteCache\IniProducer;
use SilentByte\LiteCache\LiteCache;
// Create the cache object with a customized configuration.
$cache = new LiteCache([
// Cache objects permanently.
'ttl' => LiteCache::EXPIRE_NEVER
]);
// Load the specified INI configuration file and cache it.
$config = $cache->cache('ini-cache', new IniProducer('./sample_data/test_ini.ini'));
echo "Host: ", $config['server']['host'], "\n",
"User: ", $config['server']['user'], "\n",
"Password: ", $config['server']['password'], "\n";
use SilentByte\LiteCache\LiteCache;
use SilentByte\LiteCache\OutputProducer;
// Create the cache object with a customized configuration.
$cache = new LiteCache([
// Specify the caching directory.
'directory' => '.litecache',
// Cache objects for 30 seconds.
'ttl' => '30 seconds'
]);
// Load the specified file and cache it.
$output = $cache->cache('script-cache', new OutputProducer(function () {