PHP code example of purpleharmonie / cache
1. Go to this page and download the library: Download purpleharmonie/cache 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/ */
purpleharmonie / cache example snippets
use Purple\Libs\Cache\Factory\PurpleCacheFactory;
$redisCache = PurpleCacheFactory::createCache('redis', [
'redis' => ['host' => 'localhost', 'port' => 6379],
'defaultTtl' => 7200,
'maxSize' => 1000,
'evictionPolicy' => 'LFU'
]);
$fileCache = PurpleCacheFactory::createCache('file', [
'cacheDir' => '/path/to/cache',
'defaultTtl' => 3600,
'maxSize' => 500,
'evictionPolicy' => 'LRU'
]);
$memoryCache = PurpleCacheFactory::createCache('memory', [
'defaultTtl' => 1800,
'maxSize' => 200,
'evictionPolicy' => 'LFU'
]);
public function __construct(string $cacheDir, int $defaultTtl = 3600, int $maxSize = 100, string $evictionPolicy = 'LRU')
$metrics = $fileCache->getMetrics();
echo "Hit Count: " . $metrics['hitCount'] . "\n";
echo "Miss Count: " . $metrics['missCount'] . "\n";
echo "Hit Ratio: " . $metrics['hitRatio'] . "\n";
echo "Item Count: " . $metrics['itemCount'] . "\n";