<?php require 'SimpleCache.php'; $cache = new SimpleCache('/path/to/cache1/dir'); $content = $cache->read('cache1'); if (!$content) { $content = mt_rand(1, 99999999); $cache->save('cache1', $content, '1 minute'); } echo 'Cache 1: ', $content, '<br />'; $cache = new SimpleCache('/path/to/cache2/dir'); $content = $cache->read('cache2'); if (!$content) { $content = mt_rand(1, 99999999); $cache->save('cache2', $content, '2 minutes'); } echo 'Cache 2: ', $content;
<?php require 'SimpleCache.php'; $cache = new SimpleCache('/path/to/cache/dir'); $feed = $cache->read('feed-phparch'); if (!$feed) { $feed = file_get_contents('http://www.phparch.com/feed/'); $cache->save('feed-phparch', $feed, '5 minutes'); } $xml = simplexml_load_string($feed); foreach ($xml->channel->item as $item) { echo '- <a href="', $item->link, '">', $item->title, '</a><br />', PHP_EOL; }