1. Go to this page and download the library: Download jarir-ahmed/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/ */
use JarirAhmed\Cache\Store\RedisStore;
$redis = Cache::repository(RedisStore::connect('127.0.0.1', 6379)); // uses ext-redis if loaded, else raw socket
$cache->tags(['users', 'profiles'])->put('u:1', $data, 3600);
$cache->tags(['users'])->flush(); // invalidate every 'users' entry at once
// distributed lock
$cache->lock('import', 30)->get(function () {
runImportOnce(); // only one process at a time
});
// single-flight: under load, ONE caller computes, the rest wait for the result
$report = $cache->rememberLocked('daily-report', 600, fn () => buildExpensiveReport());
use JarirAhmed\Cache\Http\HttpCache;
use JarirAhmed\Cache\Http\CacheControl;
echo HttpCache::serve($body, [
'etag' => true,
'cache_control' => CacheControl::make()->public()->maxAge(300)->staleWhileRevalidate(60),
]); // emits ETag + Cache-Control, replies 304 automatically on If-None-Match
use JarirAhmed\Cache\Http\PageCache;
$page = new PageCache($cache->store(), ttl: 120);
if (($html = $page->start('home')) !== null) { echo $html; return; } // cache hit
// ... render your page ...
echo $page->end('home'); // capture + store
use JarirAhmed\Cache\Http\CacheMiddleware;
$app->add(new CacheMiddleware($cache->store(), $psr17ResponseFactory, ttl: 60));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.