Framework solution
While the motivation for a cache tends to go from the requirement down into the mechanisms, it is easier to explain the workings of cache by starting at the bottom.
Abstract cache class
We start with an abstract cache class. Although it cannot be instantiated, it provides the actual mechanisms. Since it is fairly short, it can be presented in full here:
abstract class aliroBasicCache { private static $mops = array(); protected $sizelimit = 0; protected $timeout = 0; protected function getBasePath () { return _ALIRO_SITE_BASE.'/cache/'; } abstract protected function getCachePath ($name); public function store ($object, $cachename='', $reportSizeError=true) { $path = $this->getCachePath($cachename ? $cachename : get_class($object)); clearstatcache(); $dir = dirname($path); if (!file_exists($dir)) $this->getFileManager()->createDirectory ($dir); if (is_object($object)) $object->aliroCacheTimer = time(); else { $givendata = $object; $object = new stdClass(); $object...