This is easy-to-use php component to add caching in your project. See index.php
for examples.
getInstance()
- inits the componentset()
- sets a cache for the key for some periodget()
- returns cached data by the keygetOrSet()
- sets a cache if it doesn't exist and returns it or returns cached datadelete()
- deletes a cache file for the keyclear()
- erases all cache data
require_once 'Cache/Cache.php';
$cache = Cache::getInstance('./runtime/cache');
$reviews = $cache->get('reviews');
if (!$reviews) {
$reviews = (new Review())->getAll();
$cache->set('reviews', $reviews);
}
or
if (!$info = $cache->get('server_info')) {
$info = $_SERVER;
$cache->set('server_info', $info);
}
or
$reviews = $cache->getOrSet('reviews', function() {
return (new Review())->getAll();
});
foreach($reviews as $review) {
echo "<h2>{$review['name']}</h2><div>{$review['text']}</div>";
}
or
echo '<pre>' . print_r($info, true) . '</pre>';