Mercurial > SimpleWebPresenter
comparison FileCacheSet.inc @ 72:7bc88fe62101
Branch merge.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 23:47:12 +0200 |
| parents | 62b9d7a35658 |
| children | 1d5166aba2c5 |
comparison
equal
deleted
inserted
replaced
| 71:218a58bb2f34 | 72:7bc88fe62101 |
|---|---|
| 3 | 3 |
| 4 include_once 'Logger.inc'; | 4 include_once 'Logger.inc'; |
| 5 $cache = ScriptIncludeCache::instance(__FILE__); | 5 $cache = ScriptIncludeCache::instance(__FILE__); |
| 6 $cache->cache_time("${baseDir}/Logger.inc"); | 6 $cache->cache_time("${baseDir}/Logger.inc"); |
| 7 | 7 |
| 8 /** | |
| 9 * Caches a set of file with timestamps | |
| 10 */ | |
| 8 class FileCacheSet { | 11 class FileCacheSet { |
| 9 private $newest = 0; | 12 private $newest = 0; |
| 10 private $files = array(); | 13 private $files = array(); |
| 11 private $parentCaches = array(); | 14 private $parentCaches = array(); |
| 12 | 15 |
| 16 /** | |
| 17 * Constructs a FileCacheSet object | |
| 18 * | |
| 19 * @param $parent optional linked parent cache to sync with | |
| 20 */ | |
| 13 protected function __construct($parent = null) { | 21 protected function __construct($parent = null) { |
| 14 if ($parent) { | 22 if ($parent) { |
| 15 $this->addParent($parent); | 23 $this->addParent($parent); |
| 16 } | 24 } |
| 17 } | 25 } |
| 18 | 26 |
| 27 /** | |
| 28 * Links up a parent cache | |
| 29 * | |
| 30 * @param $parent cache we should sync with | |
| 31 */ | |
| 19 protected function addParent($parent) | 32 protected function addParent($parent) |
| 20 { | 33 { |
| 21 array_push($this->parentCaches, $parent); | 34 array_push($this->parentCaches, $parent); |
| 22 } | 35 } |
| 23 | 36 |
| 61 if ($mtime > $this->newest) { | 74 if ($mtime > $this->newest) { |
| 62 $this->newest = $mtime; | 75 $this->newest = $mtime; |
| 63 } | 76 } |
| 64 } | 77 } |
| 65 | 78 |
| 79 /** | |
| 80 * Find the newest member of the combined cacheset | |
| 81 * | |
| 82 * @return timestamp of newest member | |
| 83 */ | |
| 66 function getNewest() | 84 function getNewest() |
| 67 { | 85 { |
| 68 $newest = 0; | 86 $newest = 0; |
| 69 foreach ($this->parentCaches as $parent) { | 87 foreach ($this->parentCaches as $parent) { |
| 70 $newest = max($newest, $parent->getNewest()); | 88 $newest = max($newest, $parent->getNewest()); |
| 72 $newest = max($newest, $this->newest); | 90 $newest = max($newest, $this->newest); |
| 73 return $newest; | 91 return $newest; |
| 74 } | 92 } |
| 75 } | 93 } |
| 76 | 94 |
| 95 /** | |
| 96 * Singleton class, keeps track of all scriptfile includes | |
| 97 * | |
| 98 * This class is typically used as a parent class of another cache | |
| 99 */ | |
| 77 class ScriptIncludeCache extends FileCacheSet | 100 class ScriptIncludeCache extends FileCacheSet |
| 78 { | 101 { |
| 79 private static $myInstance = 0; | 102 private static $myInstance = 0; |
| 80 | 103 |
| 81 protected function __construct($filename = False) | 104 protected function __construct($filename = False) |
