@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * Cache constructor (this is a singleton). |
| 15 | 15 | * |
| 16 | - * @return Cache The cache singleton. |
|
| 16 | + * @return CacheAPC The cache singleton. |
|
| 17 | 17 | */ |
| 18 | 18 | static public function singleton() { |
| 19 | 19 | static $instances; |
@@ -46,6 +46,9 @@ discard block |
||
| 46 | 46 | return parent::enable(); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /** |
|
| 50 | + * @param string $sub |
|
| 51 | + */ |
|
| 49 | 52 | private function checkValidArgs($base, $id, $sub) { |
| 50 | 53 | if (is_array($base) || is_array($id) || !is_string($sub)) { |
| 51 | 54 | throw new CacheInvalidDataException('Invalid get parameter'); |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | /** |
| 46 | 46 | * Constructor. |
| 47 | 47 | * @codeCoverageIgnore |
| 48 | - */ |
|
| 48 | + */ |
|
| 49 | 49 | private function __construct() { |
| 50 | 50 | $this->lifetime = 3600 * 24 * 30; |
| 51 | 51 | $this->enable(); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * Cache constructor (this is a singleton). |
| 27 | 27 | * |
| 28 | - * @return CacheFS The cache singleton. |
|
| 28 | + * @return CacheFilesystem The cache singleton. |
|
| 29 | 29 | */ |
| 30 | 30 | static public function singleton() { |
| 31 | 31 | static $instances; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @param string $path |
| 58 | 58 | * @throws RuntimeException |
| 59 | - * @return CacheFS |
|
| 59 | + * @return CacheFilesystem |
|
| 60 | 60 | * @codeCoverageIgnore |
| 61 | 61 | */ |
| 62 | 62 | public function setPath($path) { |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | /** |
| 46 | 46 | * Constructor. |
| 47 | 47 | * @codeCoverageIgnore |
| 48 | - */ |
|
| 48 | + */ |
|
| 49 | 49 | private function __construct() { |
| 50 | 50 | $this->lifetime = 3600 * 24 * 30; |
| 51 | 51 | $this->enable(); |
@@ -118,8 +118,7 @@ discard block |
||
| 118 | 118 | $group = $this->hashKey($k); |
| 119 | 119 | if (!is_string($k->sub)) { |
| 120 | 120 | $cacheid = md5(serialize($k->sub)); |
| 121 | - } |
|
| 122 | - else { |
|
| 121 | + } else { |
|
| 123 | 122 | $cacheid = $k->sub; |
| 124 | 123 | } |
| 125 | 124 | $retval = $this->cache->get($cacheid, $group); |
@@ -149,8 +148,7 @@ discard block |
||
| 149 | 148 | $group = $this->hashKey($k); |
| 150 | 149 | if (!is_string($k->sub)) { |
| 151 | 150 | $cacheid = md5(serialize($k->sub)); |
| 152 | - } |
|
| 153 | - else { |
|
| 151 | + } else { |
|
| 154 | 152 | $cacheid = $k->sub; |
| 155 | 153 | } |
| 156 | 154 | return $this->cache->save( |
@@ -166,8 +164,7 @@ discard block |
||
| 166 | 164 | $group = $this->hashKey($k); |
| 167 | 165 | if (!is_string($k->sub)) { |
| 168 | 166 | $cacheid = md5(serialize($k->sub)); |
| 169 | - } |
|
| 170 | - else { |
|
| 167 | + } else { |
|
| 171 | 168 | $cacheid = $k->sub; |
| 172 | 169 | } |
| 173 | 170 | $this->log(CacheLogEnum::DELETED, $k); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use Cachearium\CacheKey; |
| 7 | 7 | use Cachearium\CacheLogEnum; |
| 8 | 8 | |
| 9 | -require_once(__DIR__ . '/external/Timed.php'); |
|
| 9 | +require_once(__DIR__.'/external/Timed.php'); |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Caches in filesystem |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | throw new RuntimeException('Invalid dir or missing permissions'); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $this->path = $path . '/'; |
|
| 67 | + $this->path = $path.'/'; |
|
| 68 | 68 | |
| 69 | 69 | // reload |
| 70 | 70 | if ($this->isEnabled()) { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @see \Cachearium\CacheAbstract::hashKey($k) |
| 93 | 93 | */ |
| 94 | 94 | protected function hashKey(CacheKey $k) { |
| 95 | - $group = $this->namespace . $k->base . $k->id; |
|
| 95 | + $group = $this->namespace.$k->base.$k->id; |
|
| 96 | 96 | return $group; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | return; |
| 231 | 231 | } |
| 232 | 232 | echo '<div class="cachearium cachearium-filesystem"><h2>Cache FS system</h2>'; |
| 233 | - echo '<h3>System is: ' . ($this->enabled ? 'enabled' : 'disabled') . '</h3>'; |
|
| 233 | + echo '<h3>System is: '.($this->enabled ? 'enabled' : 'disabled').'</h3>'; |
|
| 234 | 234 | echo '<ul>'; |
| 235 | 235 | foreach ($this->cache_log as $entry) { |
| 236 | - echo '<li>' . CacheLogEnum::getName($entry['status']) . $entry['message'] . '</li>'; |
|
| 236 | + echo '<li>'.CacheLogEnum::getName($entry['status']).$entry['message'].'</li>'; |
|
| 237 | 237 | } |
| 238 | 238 | echo '</ul></div>'; |
| 239 | 239 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | * |
| 30 | 30 | * @param $serves optional. If present, addServers() is called with this parameter |
| 31 | 31 | * but only if the singleton is being created for the first time. |
| 32 | - * @return Cache The cache singleton. |
|
| 32 | + * @return CacheMemcached The cache singleton. |
|
| 33 | 33 | * @codeCoverageIgnore |
| 34 | 34 | */ |
| 35 | 35 | static public function singleton($servers = []) { |
@@ -151,8 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | if (!is_string($k->sub)) { |
| 153 | 153 | $sub = md5(serialize($k->sub)); |
| 154 | - } |
|
| 155 | - else { |
|
| 154 | + } else { |
|
| 156 | 155 | $sub = $k->sub; |
| 157 | 156 | } |
| 158 | 157 | $group .= $sub; |
@@ -179,8 +178,7 @@ discard block |
||
| 179 | 178 | $this->should_log = $should_log; |
| 180 | 179 | $this->log(CacheLogEnum::PREFETCHED, $k); |
| 181 | 180 | return $data; |
| 182 | - } |
|
| 183 | - catch (NotCachedException $e) { |
|
| 181 | + } catch (NotCachedException $e) { |
|
| 184 | 182 | $this->should_log = $should_log; |
| 185 | 183 | } |
| 186 | 184 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | 133 | private function getGroupString(CacheKey $k) { |
| 134 | - return md5(strtr($this->namespace . $k->getBase() . $k->getId(), ' ', '_')); |
|
| 134 | + return md5(strtr($this->namespace.$k->getBase().$k->getId(), ' ', '_')); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $ns_key = 1; |
| 148 | 148 | $this->memcached->set($group, $ns_key); |
| 149 | 149 | } |
| 150 | - $group = $group . $ns_key; |
|
| 150 | + $group = $group.$ns_key; |
|
| 151 | 151 | |
| 152 | 152 | if (!is_string($k->sub)) { |
| 153 | 153 | $sub = md5(serialize($k->sub)); |
@@ -349,20 +349,20 @@ discard block |
||
| 349 | 349 | .cache-cleaned { background-color: #F894F8; border-radius: 3px; color: #FFF; padding: 2px 4px; } |
| 350 | 350 | </style>'; |
| 351 | 351 | echo '<div class="cachearium cachearium-memcache"><h2>Cache MemCache system</h2>'; |
| 352 | - echo '<h3>System is: ' . ($this->enabled ? 'enabled' : 'disabled') . '</h3>'; |
|
| 353 | - echo '<h3>Total fetches: ' . ($this->fetches) . '</h3>'; |
|
| 352 | + echo '<h3>System is: '.($this->enabled ? 'enabled' : 'disabled').'</h3>'; |
|
| 353 | + echo '<h3>Total fetches: '.($this->fetches).'</h3>'; |
|
| 354 | 354 | |
| 355 | 355 | $stats = array_fill_keys(array_keys(CacheLogEnum::getNames()), 0); |
| 356 | 356 | echo '<ul>'; |
| 357 | 357 | foreach ($this->cache_log as $entry) { |
| 358 | - echo '<li>' . CacheLogEnum::getName($entry['status']) . $entry['message'] . '</li>'; |
|
| 358 | + echo '<li>'.CacheLogEnum::getName($entry['status']).$entry['message'].'</li>'; |
|
| 359 | 359 | $stats[$entry['status']]++; |
| 360 | 360 | } |
| 361 | 361 | echo '</ul>'; |
| 362 | 362 | |
| 363 | 363 | echo '<ul>'; |
| 364 | 364 | foreach ($stats as $key => $val) { |
| 365 | - echo '<li>' . CacheLogEnum::getName($key) . '=' . $val . '</li>'; |
|
| 365 | + echo '<li>'.CacheLogEnum::getName($key).'='.$val.'</li>'; |
|
| 366 | 366 | } |
| 367 | 367 | echo '</ul>'; |
| 368 | 368 | echo '</div>'; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | - * @return True if cache is enabled, working and storing/retrieving data. |
|
| 161 | + * @return boolean if cache is enabled, working and storing/retrieving data. |
|
| 162 | 162 | */ |
| 163 | 163 | public function isEnabled() { |
| 164 | 164 | return $this->enabled; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * |
| 169 | - * @param number $lifetime 0 for infinite |
|
| 169 | + * @param integer $lifetime 0 for infinite |
|
| 170 | 170 | */ |
| 171 | 171 | public function setDefaultLifetime($lifetime = 0) { |
| 172 | 172 | $this->lifetime = $lifetime; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * Get cached entry. |
| 196 | 196 | * |
| 197 | 197 | * @param $k |
| 198 | - * @return mixed |
|
| 198 | + * @return string |
|
| 199 | 199 | * @throws Cachearium\Exceptions\NotCachedException |
| 200 | 200 | */ |
| 201 | 201 | abstract public function get(CacheKey $k); |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | /** |
| 305 | 305 | * Same as store() but expanded parameters |
| 306 | 306 | * |
| 307 | - * @param mixed $data |
|
| 307 | + * @param CacheData $data |
|
| 308 | 308 | * @param string $base |
| 309 | 309 | * @param string $sub |
| 310 | 310 | * @param string $id |
| 311 | - * @param number $lifetime |
|
| 311 | + * @param integer $lifetime |
|
| 312 | 312 | * @return boolean true if no problem |
| 313 | 313 | * @see store() |
| 314 | 314 | */ |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * Same as store() but expanded parameters |
| 321 | 321 | * |
| 322 | 322 | * @param CacheData $data |
| 323 | - * @param number $lifetime |
|
| 323 | + * @param integer $lifetime |
|
| 324 | 324 | * @return boolean true if no problem |
| 325 | 325 | * @see store() |
| 326 | 326 | */ |
@@ -360,6 +360,8 @@ discard block |
||
| 360 | 360 | /** |
| 361 | 361 | * Cleans cache: all entries with a certain $base and $id |
| 362 | 362 | * |
| 363 | + * @param string $base |
|
| 364 | + * @param string $id |
|
| 363 | 365 | * @return boolean true if no problem |
| 364 | 366 | */ |
| 365 | 367 | abstract public function cleanP($base, $id); |
@@ -395,7 +397,7 @@ discard block |
||
| 395 | 397 | * @param boolean $print if True echoes the data |
| 396 | 398 | * @param boolean $fail if false throws an exception if something happens, such |
| 397 | 399 | * as not cached |
| 398 | - * @return boolean|string True if cached |
|
| 400 | + * @return false|string True if cached |
|
| 399 | 401 | * @review |
| 400 | 402 | */ |
| 401 | 403 | public function start(CacheKey $k, $lifetime = null, $print = true, $fail = false) { |
@@ -484,7 +486,7 @@ discard block |
||
| 484 | 486 | |
| 485 | 487 | /** |
| 486 | 488 | * Get extra sub |
| 487 | - * @param unknown $sub |
|
| 489 | + * @param string $sub |
|
| 488 | 490 | */ |
| 489 | 491 | private function extraSub(&$sub) { |
| 490 | 492 | if (!is_callable('application_cacheDependencies')) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Is log enabled? Log can take a lot of RAM, so only turn this on when |
| 68 | 68 | * profiling. |
| 69 | 69 | * @var boolean $should_log |
| 70 | - */ |
|
| 70 | + */ |
|
| 71 | 71 | protected $should_log = false; |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * Generates a report for this backend |
| 384 | 384 | * |
| 385 | 385 | * @codeCoverageIgnore |
| 386 | - */ |
|
| 386 | + */ |
|
| 387 | 387 | abstract public function report(); |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -130,8 +130,7 @@ discard block |
||
| 130 | 130 | final public function setEnabled($b) { |
| 131 | 131 | if ($b) { |
| 132 | 132 | $this->enable(); |
| 133 | - } |
|
| 134 | - else { |
|
| 133 | + } else { |
|
| 135 | 134 | $this->disable(); |
| 136 | 135 | } |
| 137 | 136 | return $this; |
@@ -259,8 +258,7 @@ discard block |
||
| 259 | 258 | foreach ($cacheid as $k => $c) { |
| 260 | 259 | try { |
| 261 | 260 | $retval[$k] = $this->get($c); |
| 262 | - } |
|
| 263 | - catch (Exceptions\NotCachedException $e) { |
|
| 261 | + } catch (Exceptions\NotCachedException $e) { |
|
| 264 | 262 | // if there is a callback, call it |
| 265 | 263 | if ($callback) { |
| 266 | 264 | $retval[$k] = call_user_func($callback, $this, $c); |
@@ -493,8 +491,7 @@ discard block |
||
| 493 | 491 | $extra = application_cacheDependencies(); |
| 494 | 492 | if (is_array($sub)) { |
| 495 | 493 | $sub['cacheExtraSubApplication'] = $extra; |
| 496 | - } |
|
| 497 | - else { |
|
| 494 | + } else { |
|
| 498 | 495 | $sub .= $extra; |
| 499 | 496 | } |
| 500 | 497 | } |
@@ -524,8 +521,7 @@ discard block |
||
| 524 | 521 | ob_clean(); |
| 525 | 522 | $this->loopdata[$this->inloop - 1]->appendData($data); |
| 526 | 523 | $this->loopdata[$this->inloop - 1]->appendRecursion($k); |
| 527 | - } |
|
| 528 | - else { |
|
| 524 | + } else { |
|
| 529 | 525 | // something was not cached below. We invalidated all cache |
| 530 | 526 | // dependencies |
| 531 | 527 | } |
@@ -661,8 +657,7 @@ discard block |
||
| 661 | 657 | $cachedata = null; |
| 662 | 658 | } |
| 663 | 659 | // TODO $this->prefetch($cachedata->getDependencies()); |
| 664 | - } |
|
| 665 | - catch (Exceptions\NotCachedException $e) { |
|
| 660 | + } catch (Exceptions\NotCachedException $e) { |
|
| 666 | 661 | } |
| 667 | 662 | |
| 668 | 663 | // found. just return it. |
@@ -693,8 +688,7 @@ discard block |
||
| 693 | 688 | // @codeCoverageIgnoreEnd |
| 694 | 689 | } |
| 695 | 690 | return $retval; |
| 696 | - } |
|
| 697 | - catch (Exceptions\NotCachedException $e) { |
|
| 691 | + } catch (Exceptions\NotCachedException $e) { |
|
| 698 | 692 | $this->delete($k); // clear recursively |
| 699 | 693 | if ($this->inloop) { |
| 700 | 694 | throw $e; |
@@ -724,8 +718,7 @@ discard block |
||
| 724 | 718 | } |
| 725 | 719 | $this->loopdata[$this->inloop - 1]->appendData($data); |
| 726 | 720 | $this->loopdata[$this->inloop - 1]->appendRecursionData($cd); |
| 727 | - } |
|
| 728 | - else { |
|
| 721 | + } else { |
|
| 729 | 722 | // something was not cached below. We invalidated all cache |
| 730 | 723 | // dependencies |
| 731 | 724 | } |
@@ -757,8 +750,7 @@ discard block |
||
| 757 | 750 | |
| 758 | 751 | try { |
| 759 | 752 | $cachedata->generateDependenciesHash($this); |
| 760 | - } |
|
| 761 | - catch (\Cachearium\Exceptions\CacheUnsupportedOperation $e) { |
|
| 753 | + } catch (\Cachearium\Exceptions\CacheUnsupportedOperation $e) { |
|
| 762 | 754 | // not much we can do here, so just keep on going |
| 763 | 755 | } |
| 764 | 756 | $mainkey = $this->keyFromDeps($cachedata->getKey(), $cachedata->dependencies); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @return CacheAbstract |
| 109 | 109 | */ |
| 110 | 110 | public static function factory($backend) { |
| 111 | - $classname = '\Cachearium\Backend\Cache' . $backend; |
|
| 111 | + $classname = '\Cachearium\Backend\Cache'.$backend; |
|
| 112 | 112 | if (!class_exists($classname)) { |
| 113 | 113 | throw new Exceptions\CacheInvalidBackendException("Class does not exist"); |
| 114 | 114 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | \Cachearium\Backend\CacheMemcached::singleton(), |
| 127 | 127 | // TODO cache apc is broken \Cachearium\Backend\CacheAPC::singleton() |
| 128 | 128 | ]; |
| 129 | - foreach($caches as $cacheInst) { |
|
| 129 | + foreach ($caches as $cacheInst) { |
|
| 130 | 130 | if ($cacheInst->isEnabled()) { |
| 131 | 131 | $cacheInst->clear(); |
| 132 | 132 | } |
@@ -579,16 +579,16 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | if ($print) { |
| 582 | - $key = "cache-" . rand(); |
|
| 582 | + $key = "cache-".rand(); |
|
| 583 | 583 | // @codeCoverageIgnoreStart |
| 584 | 584 | if (static::$debugOnPage) { |
| 585 | 585 | echo '<span class="debug-probe-begin" |
| 586 | - data-key="' . $key . |
|
| 587 | - '" data-base="' . $cachedata->getKey()->base . |
|
| 588 | - '" data-id="' . $cachedata->getKey()->id . |
|
| 589 | - '" data-sub="' . print_r($cachedata->getKey()->sub, true) . |
|
| 590 | - '" data-lifetime="' . $cachedata->lifetime . |
|
| 591 | - '" data-backend="' . get_class($this) . |
|
| 586 | + data-key="' . $key. |
|
| 587 | + '" data-base="'.$cachedata->getKey()->base. |
|
| 588 | + '" data-id="'.$cachedata->getKey()->id. |
|
| 589 | + '" data-sub="'.print_r($cachedata->getKey()->sub, true). |
|
| 590 | + '" data-lifetime="'.$cachedata->lifetime. |
|
| 591 | + '" data-backend="'.get_class($this). |
|
| 592 | 592 | '" data-type="save"></span>'; |
| 593 | 593 | } |
| 594 | 594 | // @codeCoverageIgnoreEnd |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | |
| 598 | 598 | // @codeCoverageIgnoreStart |
| 599 | 599 | if (static::$debugOnPage) { |
| 600 | - echo '<span class="debug-probe-end" data-key="' . $key . '"></span>'; |
|
| 600 | + echo '<span class="debug-probe-end" data-key="'.$key.'"></span>'; |
|
| 601 | 601 | } |
| 602 | 602 | // @codeCoverageIgnoreEnd |
| 603 | 603 | return; |
@@ -616,13 +616,13 @@ discard block |
||
| 616 | 616 | */ |
| 617 | 617 | protected function printProbeStart($key, CacheData $cachedata, $type) { |
| 618 | 618 | echo '<span class="cachearium-debug-probe-begin" |
| 619 | - data-key="' . $key . |
|
| 620 | - '" data-base="' . $cachedata->getKey()->base . |
|
| 621 | - '" data-id="' . $cachedata->getKey()->id . |
|
| 622 | - '" data-sub="' . print_r($cachedata->getKey()->sub, true) . |
|
| 623 | - '" data-lifetime="' . $cachedata->lifetime . |
|
| 624 | - '" data-backend="' . get_class($this) . |
|
| 625 | - '" data-type="' . $type . '"></span>'; |
|
| 619 | + data-key="' . $key. |
|
| 620 | + '" data-base="'.$cachedata->getKey()->base. |
|
| 621 | + '" data-id="'.$cachedata->getKey()->id. |
|
| 622 | + '" data-sub="'.print_r($cachedata->getKey()->sub, true). |
|
| 623 | + '" data-lifetime="'.$cachedata->lifetime. |
|
| 624 | + '" data-backend="'.get_class($this). |
|
| 625 | + '" data-type="'.$type.'"></span>'; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | * @codeCoverageIgnore |
| 635 | 635 | */ |
| 636 | 636 | protected function printProbeEnd($key, CacheData $cachedata) { |
| 637 | - echo '<span class="cachearium-debug-probe-end" data-key="' . $key . '"></span>'; |
|
| 637 | + echo '<span class="cachearium-debug-probe-end" data-key="'.$key.'"></span>'; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | $cachedata->key, |
| 685 | 685 | $cachedata->lifetime |
| 686 | 686 | ); |
| 687 | - $key = "cache-" . rand(); |
|
| 687 | + $key = "cache-".rand(); |
|
| 688 | 688 | |
| 689 | 689 | $retval = $cachedata->stringify($this); |
| 690 | 690 | |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | if ($print) { |
| 791 | - $key = "cache-" . rand(); |
|
| 791 | + $key = "cache-".rand(); |
|
| 792 | 792 | // @codeCoverageIgnoreStart |
| 793 | 793 | if (static::$debugOnPage) { |
| 794 | 794 | $this->printProbeStart($key, $cachedata, 'save'); |
@@ -851,10 +851,10 @@ discard block |
||
| 851 | 851 | foreach ($bt as $i => $d) { |
| 852 | 852 | if (strpos($d['file'], '/Cache') === false) { |
| 853 | 853 | // TODO: if() may not work well if user has a file called Cache |
| 854 | - $trace = $d['function'] . ' at ' . $d['file'] . ':' . $d['line']; |
|
| 854 | + $trace = $d['function'].' at '.$d['file'].':'.$d['line']; |
|
| 855 | 855 | $this->cache_log[] = array( |
| 856 | 856 | 'status' => $status, |
| 857 | - 'message' => "(" . $k->debug() . ", $lifetime) by " . $trace |
|
| 857 | + 'message' => "(".$k->debug().", $lifetime) by ".$trace |
|
| 858 | 858 | ); |
| 859 | 859 | break; |
| 860 | 860 | } |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | public static function dumpSummary() { |
| 869 | 869 | echo '<div id="cache-summary">Cache Summary (non-ajax): '; |
| 870 | 870 | foreach (static::getLogSummary() as $key => $val) { |
| 871 | - echo $key . '=>' . $val . ' / '; |
|
| 871 | + echo $key.'=>'.$val.' / '; |
|
| 872 | 872 | } |
| 873 | 873 | echo '</div>'; |
| 874 | 874 | } |
@@ -214,7 +214,6 @@ |
||
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * Adds a dependency |
| 217 | - * @param array<CacheKey> $k |
|
| 218 | 217 | * @return CacheData This |
| 219 | 218 | */ |
| 220 | 219 | public function addDependencies(array $deps) { |
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | public function dependencyInit(CacheAbstract $cache, CacheKey $k) { |
| 111 | 111 | try { |
| 112 | 112 | return $cache->increment(0, $k, 0); |
| 113 | - } |
|
| 114 | - catch (\Cachearium\Exceptions\CacheUnsupportedOperation $e) { |
|
| 113 | + } catch (\Cachearium\Exceptions\CacheUnsupportedOperation $e) { |
|
| 115 | 114 | return 0; |
| 116 | 115 | } |
| 117 | 116 | } |
@@ -272,23 +271,19 @@ discard block |
||
| 272 | 271 | $callback = $item['data']; |
| 273 | 272 | if (is_callable($callback)) { |
| 274 | 273 | $retval[] = call_user_func($callback); |
| 275 | - } |
|
| 276 | - else { |
|
| 274 | + } else { |
|
| 277 | 275 | // throw? |
| 278 | 276 | } |
| 279 | - } |
|
| 280 | - else if ($item['type'] == self::CACHEDATA_TYPE_RECURSION) { |
|
| 277 | + } else if ($item['type'] == self::CACHEDATA_TYPE_RECURSION) { |
|
| 281 | 278 | if ($recurse) { |
| 282 | 279 | $retval[] = $c->get($item['data']); |
| 283 | 280 | } |
| 284 | - } |
|
| 285 | - else if ($item['type'] == self::CACHEDATA_TYPE_RECURSION_DATA) { |
|
| 281 | + } else if ($item['type'] == self::CACHEDATA_TYPE_RECURSION_DATA) { |
|
| 286 | 282 | if ($recurse) { |
| 287 | 283 | $data = $c->getData($item['data']); |
| 288 | 284 | $retval[] = $data->stringify($c); |
| 289 | 285 | } |
| 290 | - } |
|
| 291 | - else { |
|
| 286 | + } else { |
|
| 292 | 287 | $retval[] = $item['data']; |
| 293 | 288 | } |
| 294 | 289 | } |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | if (!is_string($k->sub)) { |
| 93 | 93 | $sub = md5(serialize($k->sub)); |
| 94 | - } |
|
| 95 | - else { |
|
| 94 | + } else { |
|
| 96 | 95 | $sub = $k->sub; |
| 97 | 96 | } |
| 98 | 97 | $this->checkValidArgs($k); |
@@ -100,8 +99,7 @@ discard block |
||
| 100 | 99 | $idx = $this->namespace . $k->base . $k->id; |
| 101 | 100 | if (isset($this->storage[$idx]) && isset($this->storage[$idx][$sub])) { |
| 102 | 101 | $this->storage[$idx][$sub] += $value; |
| 103 | - } |
|
| 104 | - else { |
|
| 102 | + } else { |
|
| 105 | 103 | $this->storage[$idx][$sub] = $default; |
| 106 | 104 | } |
| 107 | 105 | return $this->storage[$idx][$sub]; |
@@ -116,8 +114,7 @@ discard block |
||
| 116 | 114 | |
| 117 | 115 | if (!is_string($k->sub)) { |
| 118 | 116 | $sub = md5(serialize($k->sub)); |
| 119 | - } |
|
| 120 | - else { |
|
| 117 | + } else { |
|
| 121 | 118 | $sub = $k->sub; |
| 122 | 119 | } |
| 123 | 120 | $this->checkValidArgs($k); |
@@ -142,8 +139,7 @@ discard block |
||
| 142 | 139 | |
| 143 | 140 | if (!is_string($k->sub)) { |
| 144 | 141 | $sub = md5(serialize($k->sub)); |
| 145 | - } |
|
| 146 | - else { |
|
| 142 | + } else { |
|
| 147 | 143 | $sub = $k->sub; |
| 148 | 144 | } |
| 149 | 145 | $this->checkValidArgs($k); |
@@ -155,8 +151,7 @@ discard block |
||
| 155 | 151 | public function delete(CacheKey $k) { |
| 156 | 152 | if (!is_string($k->sub)) { |
| 157 | 153 | $sub = md5(serialize($k->sub)); |
| 158 | - } |
|
| 159 | - else { |
|
| 154 | + } else { |
|
| 160 | 155 | $sub = $k->sub; |
| 161 | 156 | } |
| 162 | 157 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | protected function hashKey(CacheKey $k) { |
| 57 | - return $this->namespace . $k->base . $k->id . serialize($k->sub); |
|
| 57 | + return $this->namespace.$k->base.$k->id.serialize($k->sub); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | $this->checkValidArgs($k); |
| 99 | 99 | |
| 100 | - $idx = $this->namespace . $k->base . $k->id; |
|
| 100 | + $idx = $this->namespace.$k->base.$k->id; |
|
| 101 | 101 | if (isset($this->storage[$idx]) && isset($this->storage[$idx][$sub])) { |
| 102 | 102 | $this->storage[$idx][$sub] += $value; |
| 103 | 103 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | $this->checkValidArgs($k); |
| 124 | 124 | |
| 125 | - $idx = $this->namespace . $k->base . $k->id; |
|
| 125 | + $idx = $this->namespace.$k->base.$k->id; |
|
| 126 | 126 | if (isset($this->storage[$idx]) |
| 127 | 127 | and array_key_exists($sub, $this->storage[$idx]) |
| 128 | 128 | ) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | $this->checkValidArgs($k); |
| 150 | 150 | |
| 151 | - $this->storage[$this->namespace . $k->base . $k->id][$sub] = $data; |
|
| 151 | + $this->storage[$this->namespace.$k->base.$k->id][$sub] = $data; |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $this->checkValidArgs($k); |
| 164 | 164 | |
| 165 | - unset($this->storage[$this->namespace . $k->base . $k->id][$sub]); |
|
| 165 | + unset($this->storage[$this->namespace.$k->base.$k->id][$sub]); |
|
| 166 | 166 | return true; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | public function cleanP($base, $id) { |
| 170 | - unset($this->storage[$this->namespace . $base . $id]); |
|
| 170 | + unset($this->storage[$this->namespace.$base.$id]); |
|
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -221,18 +221,18 @@ discard block |
||
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | 223 | echo '<div><h2>Cache RAM system</h2>'; |
| 224 | - echo '<h3>System is: ' . ($this->enabled ? 'enabled' : 'disabled') . '</h3>'; |
|
| 224 | + echo '<h3>System is: '.($this->enabled ? 'enabled' : 'disabled').'</h3>'; |
|
| 225 | 225 | $stats = array_fill_keys(array_keys(CacheLogEnum::getNames()), 0); |
| 226 | 226 | echo '<ul>'; |
| 227 | 227 | foreach ($this->cache_log as $entry) { |
| 228 | - echo '<li>' . CacheLogEnum::getName($entry['status']) . $entry['message'] . '</li>'; |
|
| 228 | + echo '<li>'.CacheLogEnum::getName($entry['status']).$entry['message'].'</li>'; |
|
| 229 | 229 | $stats[$entry['status']]++; |
| 230 | 230 | } |
| 231 | 231 | echo '</ul>'; |
| 232 | 232 | |
| 233 | 233 | echo '<ul>'; |
| 234 | 234 | foreach ($stats as $key => $val) { |
| 235 | - echo '<li>' . CacheLogEnum::getName($key) . '=' . $val . '</li>'; |
|
| 235 | + echo '<li>'.CacheLogEnum::getName($key).'='.$val.'</li>'; |
|
| 236 | 236 | } |
| 237 | 237 | echo '</ul>'; |
| 238 | 238 | |
@@ -805,14 +805,14 @@ |
||
| 805 | 805 | function _hash($data, $controlType) |
| 806 | 806 | { |
| 807 | 807 | switch ($controlType) { |
| 808 | - case 'md5': |
|
| 809 | - return md5($data); |
|
| 810 | - case 'crc32': |
|
| 811 | - return sprintf('% 32d', crc32($data)); |
|
| 812 | - case 'strlen': |
|
| 813 | - return sprintf('% 32d', strlen($data)); |
|
| 814 | - default: |
|
| 815 | - return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 808 | + case 'md5': |
|
| 809 | + return md5($data); |
|
| 810 | + case 'crc32': |
|
| 811 | + return sprintf('% 32d', crc32($data)); |
|
| 812 | + case 'strlen': |
|
| 813 | + return sprintf('% 32d', strlen($data)); |
|
| 814 | + default: |
|
| 815 | + return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 816 | 816 | } |
| 817 | 817 | } |
| 818 | 818 | |
@@ -700,7 +700,9 @@ discard block |
||
| 700 | 700 | function _read() |
| 701 | 701 | { |
| 702 | 702 | $fp = @fopen($this->_file, "rb"); |
| 703 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 703 | + if ($this->_fileLocking) { |
|
| 704 | + @flock($fp, LOCK_SH); |
|
| 705 | + } |
|
| 704 | 706 | if ($fp) { |
| 705 | 707 | clearstatcache(); |
| 706 | 708 | $length = @filesize($this->_file); |
@@ -716,7 +718,9 @@ discard block |
||
| 716 | 718 | $data = ''; |
| 717 | 719 | } |
| 718 | 720 | // set_magic_quotes_runtime($mqr); |
| 719 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 721 | + if ($this->_fileLocking) { |
|
| 722 | + @flock($fp, LOCK_UN); |
|
| 723 | + } |
|
| 720 | 724 | @fclose($fp); |
| 721 | 725 | if ($this->_readControl) { |
| 722 | 726 | $hashData = $this->_hash($data, $this->_readControlType); |
@@ -756,13 +760,17 @@ discard block |
||
| 756 | 760 | } |
| 757 | 761 | $fp = @fopen($this->_file, "wb"); |
| 758 | 762 | if ($fp) { |
| 759 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 763 | + if ($this->_fileLocking) { |
|
| 764 | + @flock($fp, LOCK_EX); |
|
| 765 | + } |
|
| 760 | 766 | if ($this->_readControl) { |
| 761 | 767 | @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
| 762 | 768 | } |
| 763 | 769 | $len = strlen($data); |
| 764 | 770 | @fwrite($fp, $data, $len); |
| 765 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 771 | + if ($this->_fileLocking) { |
|
| 772 | + @flock($fp, LOCK_UN); |
|
| 773 | + } |
|
| 766 | 774 | @fclose($fp); |
| 767 | 775 | umask($oldmask); |
| 768 | 776 | return true; |
@@ -29,792 +29,792 @@ |
||
| 29 | 29 | class Cache_Lite |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - // --- Private properties --- |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Directory where to put the cache files |
|
| 36 | - * (make sure to add a trailing slash) |
|
| 37 | - * |
|
| 38 | - * @var string $_cacheDir |
|
| 39 | - */ |
|
| 40 | - var $_cacheDir = '/tmp/'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Enable / disable caching |
|
| 44 | - * |
|
| 45 | - * (can be very usefull for the debug of cached scripts) |
|
| 46 | - * |
|
| 47 | - * @var boolean $_caching |
|
| 48 | - */ |
|
| 49 | - var $_caching = true; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Cache lifetime (in seconds) |
|
| 53 | - * |
|
| 54 | - * If null, the cache is valid forever. |
|
| 55 | - * |
|
| 56 | - * @var int $_lifeTime |
|
| 57 | - */ |
|
| 58 | - var $_lifeTime = 3600; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Enable / disable fileLocking |
|
| 62 | - * |
|
| 63 | - * (can avoid cache corruption under bad circumstances) |
|
| 64 | - * |
|
| 65 | - * @var boolean $_fileLocking |
|
| 66 | - */ |
|
| 67 | - var $_fileLocking = true; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Timestamp of the last valid cache |
|
| 71 | - * |
|
| 72 | - * @var int $_refreshTime |
|
| 73 | - */ |
|
| 74 | - var $_refreshTime; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * File name (with path) |
|
| 78 | - * |
|
| 79 | - * @var string $_file |
|
| 80 | - */ |
|
| 81 | - var $_file; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * File name (without path) |
|
| 85 | - * |
|
| 86 | - * @var string $_fileName |
|
| 87 | - */ |
|
| 88 | - var $_fileName; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Enable / disable write control (the cache is read just after writing to detect corrupt entries) |
|
| 92 | - * |
|
| 93 | - * Enable write control will lightly slow the cache writing but not the cache reading |
|
| 94 | - * Write control can detect some corrupt cache files but maybe it's not a perfect control |
|
| 95 | - * |
|
| 96 | - * @var boolean $_writeControl |
|
| 97 | - */ |
|
| 98 | - var $_writeControl = true; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Enable / disable read control |
|
| 102 | - * |
|
| 103 | - * If enabled, a control key is embeded in cache file and this key is compared with the one |
|
| 104 | - * calculated after the reading. |
|
| 105 | - * |
|
| 106 | - * @var boolean $_writeControl |
|
| 107 | - */ |
|
| 108 | - var $_readControl = false; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Type of read control (only if read control is enabled) |
|
| 112 | - * |
|
| 113 | - * Available values are : |
|
| 114 | - * 'md5' for a md5 hash control (best but slowest) |
|
| 115 | - * 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) |
|
| 116 | - * 'strlen' for a length only test (fastest) |
|
| 117 | - * |
|
| 118 | - * @var boolean $_readControlType |
|
| 119 | - */ |
|
| 120 | - var $_readControlType = 'crc32'; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Pear error mode (when raiseError is called) |
|
| 124 | - * |
|
| 125 | - * (see PEAR doc) |
|
| 126 | - * |
|
| 127 | - * @see setToDebug() |
|
| 128 | - * @var int $_pearErrorMode |
|
| 129 | - */ |
|
| 130 | - var $_pearErrorMode = CACHE_LITE_ERROR_RETURN; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Current cache id |
|
| 134 | - * |
|
| 135 | - * @var string $_id |
|
| 136 | - */ |
|
| 137 | - var $_id; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Current cache group |
|
| 141 | - * |
|
| 142 | - * @var string $_group |
|
| 143 | - */ |
|
| 144 | - var $_group; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Enable / Disable "Memory Caching" |
|
| 148 | - * |
|
| 149 | - * NB : There is no lifetime for memory caching ! |
|
| 150 | - * |
|
| 151 | - * @var boolean $_memoryCaching |
|
| 152 | - */ |
|
| 153 | - var $_memoryCaching = false; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Enable / Disable "Only Memory Caching" |
|
| 157 | - * (be carefull, memory caching is "beta quality") |
|
| 158 | - * |
|
| 159 | - * @var boolean $_onlyMemoryCaching |
|
| 160 | - */ |
|
| 161 | - var $_onlyMemoryCaching = false; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Memory caching array |
|
| 165 | - * |
|
| 166 | - * @var array $_memoryCachingArray |
|
| 167 | - */ |
|
| 168 | - var $_memoryCachingArray = array(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Memory caching counter |
|
| 172 | - * |
|
| 173 | - * @var int $memoryCachingCounter |
|
| 174 | - */ |
|
| 175 | - var $_memoryCachingCounter = 0; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Memory caching limit |
|
| 179 | - * |
|
| 180 | - * @var int $memoryCachingLimit |
|
| 181 | - */ |
|
| 182 | - var $_memoryCachingLimit = 1000; |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * File Name protection |
|
| 186 | - * |
|
| 187 | - * if set to true, you can use any cache id or group name |
|
| 188 | - * if set to false, it can be faster but cache ids and group names |
|
| 189 | - * will be used directly in cache file names so be carefull with |
|
| 190 | - * special characters... |
|
| 191 | - * |
|
| 192 | - * @var boolean $fileNameProtection |
|
| 193 | - */ |
|
| 194 | - var $_fileNameProtection = true; |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Enable / disable automatic serialization |
|
| 198 | - * |
|
| 199 | - * it can be used to save directly datas which aren't strings |
|
| 200 | - * (but it's slower) |
|
| 201 | - * |
|
| 202 | - * @var boolean $_serialize |
|
| 203 | - */ |
|
| 204 | - var $_automaticSerialization = false; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Disable / Tune the automatic cleaning process |
|
| 208 | - * |
|
| 209 | - * The automatic cleaning process destroy too old (for the given life time) |
|
| 210 | - * cache files when a new cache file is written. |
|
| 211 | - * 0 => no automatic cache cleaning |
|
| 212 | - * 1 => systematic cache cleaning |
|
| 213 | - * x (integer) > 1 => automatic cleaning randomly 1 times on x cache write |
|
| 214 | - * |
|
| 215 | - * @var int $_automaticCleaning |
|
| 216 | - */ |
|
| 217 | - var $_automaticCleaningFactor = 0; |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Nested directory level |
|
| 221 | - * |
|
| 222 | - * Set the hashed directory structure level. 0 means "no hashed directory |
|
| 223 | - * structure", 1 means "one level of directory", 2 means "two levels"... |
|
| 224 | - * This option can speed up Cache_Lite only when you have many thousands of |
|
| 225 | - * cache file. Only specific benchs can help you to choose the perfect value |
|
| 226 | - * for you. Maybe, 1 or 2 is a good start. |
|
| 227 | - * |
|
| 228 | - * @var int $_hashedDirectoryLevel |
|
| 229 | - */ |
|
| 230 | - var $_hashedDirectoryLevel = 0; |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Umask for hashed directory structure |
|
| 234 | - * |
|
| 235 | - * @var int $_hashedDirectoryUmask |
|
| 236 | - */ |
|
| 237 | - var $_hashedDirectoryUmask = 0770; |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * API break for error handling in CACHE_LITE_ERROR_RETURN mode |
|
| 241 | - * |
|
| 242 | - * In CACHE_LITE_ERROR_RETURN mode, error handling was not good because |
|
| 243 | - * for example save() method always returned a boolean (a PEAR_Error object |
|
| 244 | - * would be better in CACHE_LITE_ERROR_RETURN mode). To correct this without |
|
| 245 | - * breaking the API, this option (false by default) can change this handling. |
|
| 246 | - * |
|
| 247 | - * @var boolean |
|
| 248 | - */ |
|
| 249 | - var $_errorHandlingAPIBreak = false; |
|
| 250 | - |
|
| 251 | - // --- Public methods --- |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Constructor |
|
| 255 | - * |
|
| 256 | - * $options is an assoc. Available options are : |
|
| 257 | - * $options = array( |
|
| 258 | - * 'cacheDir' => directory where to put the cache files (string), |
|
| 259 | - * 'caching' => enable / disable caching (boolean), |
|
| 260 | - * 'lifeTime' => cache lifetime in seconds (int), |
|
| 261 | - * 'fileLocking' => enable / disable fileLocking (boolean), |
|
| 262 | - * 'writeControl' => enable / disable write control (boolean), |
|
| 263 | - * 'readControl' => enable / disable read control (boolean), |
|
| 264 | - * 'readControlType' => type of read control 'crc32', 'md5', 'strlen' (string), |
|
| 265 | - * 'pearErrorMode' => pear error mode (when raiseError is called) (cf PEAR doc) (int), |
|
| 266 | - * 'memoryCaching' => enable / disable memory caching (boolean), |
|
| 267 | - * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
| 268 | - * 'memoryCachingLimit' => max nbr of records to store into memory caching (int), |
|
| 269 | - * 'fileNameProtection' => enable / disable automatic file name protection (boolean), |
|
| 270 | - * 'automaticSerialization' => enable / disable automatic serialization (boolean), |
|
| 271 | - * 'automaticCleaningFactor' => distable / tune automatic cleaning process (int), |
|
| 272 | - * 'hashedDirectoryLevel' => level of the hashed directory system (int), |
|
| 273 | - * 'hashedDirectoryUmask' => umask for hashed directory structure (int), |
|
| 274 | - * 'errorHandlingAPIBreak' => API break for better error handling ? (boolean) |
|
| 275 | - * ); |
|
| 276 | - * |
|
| 277 | - * @param array $options options |
|
| 278 | - * @access public |
|
| 279 | - */ |
|
| 280 | - function __construct($options = array(NULL)) |
|
| 281 | - { |
|
| 282 | - foreach($options as $key => $value) { |
|
| 283 | - $this->setOption($key, $value); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Generic way to set a Cache_Lite option |
|
| 289 | - * |
|
| 290 | - * see Cache_Lite constructor for available options |
|
| 291 | - * |
|
| 292 | - * @var string $name name of the option |
|
| 293 | - * @var mixed $value value of the option |
|
| 294 | - * @access public |
|
| 295 | - */ |
|
| 296 | - function setOption($name, $value) |
|
| 297 | - { |
|
| 298 | - $availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode'); |
|
| 299 | - if (in_array($name, $availableOptions)) { |
|
| 300 | - $property = '_'.$name; |
|
| 301 | - $this->$property = $value; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Test if a cache is available and (if yes) return it |
|
| 307 | - * |
|
| 308 | - * @param string $id cache id |
|
| 309 | - * @param string $group name of the cache group |
|
| 310 | - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 311 | - * @return string data of the cache (else : false) |
|
| 312 | - * @access public |
|
| 313 | - */ |
|
| 314 | - function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 315 | - { |
|
| 316 | - $this->_id = $id; |
|
| 317 | - $this->_group = $group; |
|
| 318 | - $data = false; |
|
| 319 | - if ($this->_caching) { |
|
| 320 | - $this->_setRefreshTime(); |
|
| 321 | - $this->_setFileName($id, $group); |
|
| 322 | - clearstatcache(); |
|
| 323 | - if ($this->_memoryCaching) { |
|
| 324 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 325 | - if ($this->_automaticSerialization) { |
|
| 326 | - return unserialize($this->_memoryCachingArray[$this->_file]); |
|
| 327 | - } |
|
| 328 | - return $this->_memoryCachingArray[$this->_file]; |
|
| 329 | - } |
|
| 330 | - if ($this->_onlyMemoryCaching) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - if (($doNotTestCacheValidity) || (is_null($this->_refreshTime))) { |
|
| 335 | - if (file_exists($this->_file)) { |
|
| 336 | - $data = $this->_read(); |
|
| 337 | - } |
|
| 338 | - } else { |
|
| 339 | - if ((file_exists($this->_file)) && (@filemtime($this->_file) > $this->_refreshTime)) { |
|
| 340 | - $data = $this->_read(); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - if (($data) and ($this->_memoryCaching)) { |
|
| 344 | - $this->_memoryCacheAdd($data); |
|
| 345 | - } |
|
| 346 | - if (($this->_automaticSerialization) and (is_string($data))) { |
|
| 347 | - $data = unserialize($data); |
|
| 348 | - } |
|
| 349 | - return $data; |
|
| 350 | - } |
|
| 351 | - return false; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Save some data in a cache file |
|
| 356 | - * |
|
| 357 | - * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 358 | - * @param string $id cache id |
|
| 359 | - * @param string $group name of the cache group |
|
| 360 | - * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 361 | - * @access public |
|
| 362 | - */ |
|
| 363 | - function save($data, $id = NULL, $group = 'default') |
|
| 364 | - { |
|
| 365 | - if ($this->_caching) { |
|
| 366 | - if ($this->_automaticSerialization) { |
|
| 367 | - $data = serialize($data); |
|
| 368 | - } |
|
| 369 | - if (isset($id)) { |
|
| 370 | - $this->_setFileName($id, $group); |
|
| 371 | - } |
|
| 372 | - if ($this->_memoryCaching) { |
|
| 373 | - $this->_memoryCacheAdd($data); |
|
| 374 | - if ($this->_onlyMemoryCaching) { |
|
| 375 | - return true; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - if ($this->_automaticCleaningFactor>0) { |
|
| 379 | - $rand = rand(1, $this->_automaticCleaningFactor); |
|
| 380 | - if ($rand==1) { |
|
| 381 | - $this->clean(false, 'old'); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - if ($this->_writeControl) { |
|
| 385 | - $res = $this->_writeAndControl($data); |
|
| 386 | - if (is_bool($res)) { |
|
| 387 | - if ($res) { |
|
| 388 | - return true; |
|
| 389 | - } |
|
| 390 | - // if $res if false, we need to invalidate the cache |
|
| 391 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 392 | - return false; |
|
| 393 | - } |
|
| 394 | - } else { |
|
| 395 | - $res = $this->_write($data); |
|
| 396 | - } |
|
| 397 | - if (is_object($res)) { |
|
| 398 | - // $res is a PEAR_Error object |
|
| 399 | - if (!($this->_errorHandlingAPIBreak)) { |
|
| 400 | - return false; // we return false (old API) |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - return $res; |
|
| 404 | - } |
|
| 405 | - return false; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Remove a cache file |
|
| 410 | - * |
|
| 411 | - * @param string $id cache id |
|
| 412 | - * @param string $group name of the cache group |
|
| 413 | - * @return boolean true if no problem |
|
| 414 | - * @access public |
|
| 415 | - */ |
|
| 416 | - function remove($id, $group = 'default') |
|
| 417 | - { |
|
| 418 | - $this->_setFileName($id, $group); |
|
| 419 | - if ($this->_memoryCaching) { |
|
| 420 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 421 | - unset($this->_memoryCachingArray[$this->_file]); |
|
| 422 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1; |
|
| 423 | - } |
|
| 424 | - if ($this->_onlyMemoryCaching) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - return $this->_unlink($this->_file); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Clean the cache |
|
| 433 | - * |
|
| 434 | - * if no group is specified all cache files will be destroyed |
|
| 435 | - * else only cache files of the specified group will be destroyed |
|
| 436 | - * |
|
| 437 | - * @param string $group name of the cache group |
|
| 438 | - * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 439 | - * 'callback_myFunction' |
|
| 440 | - * @return boolean true if no problem |
|
| 441 | - * @access public |
|
| 442 | - */ |
|
| 443 | - function clean($group = false, $mode = 'ingroup') |
|
| 444 | - { |
|
| 445 | - return $this->_cleanDir($this->_cacheDir, $group, $mode); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Set to debug mode |
|
| 450 | - * |
|
| 451 | - * When an error is found, the script will stop and the message will be displayed |
|
| 452 | - * (in debug mode only). |
|
| 453 | - * |
|
| 454 | - * @access public |
|
| 455 | - */ |
|
| 456 | - function setToDebug() |
|
| 457 | - { |
|
| 458 | - $this->setOption('pearErrorMode', CACHE_LITE_ERROR_DIE); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Set a new life time |
|
| 463 | - * |
|
| 464 | - * @param int $newLifeTime new life time (in seconds) |
|
| 465 | - * @access public |
|
| 466 | - */ |
|
| 467 | - function setLifeTime($newLifeTime) |
|
| 468 | - { |
|
| 469 | - $this->_lifeTime = $newLifeTime; |
|
| 470 | - $this->_setRefreshTime(); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Save the state of the caching memory array into a cache file cache |
|
| 475 | - * |
|
| 476 | - * @param string $id cache id |
|
| 477 | - * @param string $group name of the cache group |
|
| 478 | - * @access public |
|
| 479 | - */ |
|
| 480 | - function saveMemoryCachingState($id, $group = 'default') |
|
| 481 | - { |
|
| 482 | - if ($this->_caching) { |
|
| 483 | - $array = array( |
|
| 484 | - 'counter' => $this->_memoryCachingCounter, |
|
| 485 | - 'array' => $this->_memoryCachingState |
|
| 486 | - ); |
|
| 487 | - $data = serialize($array); |
|
| 488 | - $this->save($data, $id, $group); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Load the state of the caching memory array from a given cache file cache |
|
| 494 | - * |
|
| 495 | - * @param string $id cache id |
|
| 496 | - * @param string $group name of the cache group |
|
| 497 | - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 498 | - * @access public |
|
| 499 | - */ |
|
| 500 | - function getMemoryCachingState($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 501 | - { |
|
| 502 | - if ($this->_caching) { |
|
| 503 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) { |
|
| 504 | - $array = unserialize($data); |
|
| 505 | - $this->_memoryCachingCounter = $array['counter']; |
|
| 506 | - $this->_memoryCachingArray = $array['array']; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Return the cache last modification time |
|
| 513 | - * |
|
| 514 | - * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 515 | - * |
|
| 516 | - * @return int last modification time |
|
| 517 | - */ |
|
| 518 | - function lastModified() |
|
| 519 | - { |
|
| 520 | - return @filemtime($this->_file); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Trigger error |
|
| 525 | - * |
|
| 526 | - * @param string $msg error message |
|
| 527 | - * @param int $code error code |
|
| 528 | - * @access public |
|
| 529 | - */ |
|
| 530 | - function raiseError($msg, $code) |
|
| 531 | - { |
|
| 532 | - return new Exception($msg); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Extend the life of a valid cache file |
|
| 537 | - * |
|
| 538 | - * see http://pear.php.net/bugs/bug.php?id=6681 |
|
| 539 | - * |
|
| 540 | - * @access public |
|
| 541 | - */ |
|
| 542 | - function extendLife() |
|
| 543 | - { |
|
| 544 | - @touch($this->_file); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // --- Private methods --- |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Compute & set the refresh time |
|
| 551 | - * |
|
| 552 | - * @access private |
|
| 553 | - */ |
|
| 554 | - function _setRefreshTime() |
|
| 555 | - { |
|
| 556 | - if (is_null($this->_lifeTime)) { |
|
| 557 | - $this->_refreshTime = null; |
|
| 558 | - } else { |
|
| 559 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Remove a file |
|
| 565 | - * |
|
| 566 | - * @param string $file complete file path and name |
|
| 567 | - * @return boolean true if no problem |
|
| 568 | - * @access private |
|
| 569 | - */ |
|
| 570 | - function _unlink($file) |
|
| 571 | - { |
|
| 572 | - if (!@unlink($file)) { |
|
| 573 | - return $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 574 | - } |
|
| 575 | - return true; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Recursive function for cleaning cache file in the given directory |
|
| 580 | - * |
|
| 581 | - * @param string $dir directory complete path (with a trailing slash) |
|
| 582 | - * @param string $group name of the cache group |
|
| 583 | - * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 32 | + // --- Private properties --- |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Directory where to put the cache files |
|
| 36 | + * (make sure to add a trailing slash) |
|
| 37 | + * |
|
| 38 | + * @var string $_cacheDir |
|
| 39 | + */ |
|
| 40 | + var $_cacheDir = '/tmp/'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Enable / disable caching |
|
| 44 | + * |
|
| 45 | + * (can be very usefull for the debug of cached scripts) |
|
| 46 | + * |
|
| 47 | + * @var boolean $_caching |
|
| 48 | + */ |
|
| 49 | + var $_caching = true; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Cache lifetime (in seconds) |
|
| 53 | + * |
|
| 54 | + * If null, the cache is valid forever. |
|
| 55 | + * |
|
| 56 | + * @var int $_lifeTime |
|
| 57 | + */ |
|
| 58 | + var $_lifeTime = 3600; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Enable / disable fileLocking |
|
| 62 | + * |
|
| 63 | + * (can avoid cache corruption under bad circumstances) |
|
| 64 | + * |
|
| 65 | + * @var boolean $_fileLocking |
|
| 66 | + */ |
|
| 67 | + var $_fileLocking = true; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Timestamp of the last valid cache |
|
| 71 | + * |
|
| 72 | + * @var int $_refreshTime |
|
| 73 | + */ |
|
| 74 | + var $_refreshTime; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * File name (with path) |
|
| 78 | + * |
|
| 79 | + * @var string $_file |
|
| 80 | + */ |
|
| 81 | + var $_file; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * File name (without path) |
|
| 85 | + * |
|
| 86 | + * @var string $_fileName |
|
| 87 | + */ |
|
| 88 | + var $_fileName; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Enable / disable write control (the cache is read just after writing to detect corrupt entries) |
|
| 92 | + * |
|
| 93 | + * Enable write control will lightly slow the cache writing but not the cache reading |
|
| 94 | + * Write control can detect some corrupt cache files but maybe it's not a perfect control |
|
| 95 | + * |
|
| 96 | + * @var boolean $_writeControl |
|
| 97 | + */ |
|
| 98 | + var $_writeControl = true; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Enable / disable read control |
|
| 102 | + * |
|
| 103 | + * If enabled, a control key is embeded in cache file and this key is compared with the one |
|
| 104 | + * calculated after the reading. |
|
| 105 | + * |
|
| 106 | + * @var boolean $_writeControl |
|
| 107 | + */ |
|
| 108 | + var $_readControl = false; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Type of read control (only if read control is enabled) |
|
| 112 | + * |
|
| 113 | + * Available values are : |
|
| 114 | + * 'md5' for a md5 hash control (best but slowest) |
|
| 115 | + * 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) |
|
| 116 | + * 'strlen' for a length only test (fastest) |
|
| 117 | + * |
|
| 118 | + * @var boolean $_readControlType |
|
| 119 | + */ |
|
| 120 | + var $_readControlType = 'crc32'; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Pear error mode (when raiseError is called) |
|
| 124 | + * |
|
| 125 | + * (see PEAR doc) |
|
| 126 | + * |
|
| 127 | + * @see setToDebug() |
|
| 128 | + * @var int $_pearErrorMode |
|
| 129 | + */ |
|
| 130 | + var $_pearErrorMode = CACHE_LITE_ERROR_RETURN; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Current cache id |
|
| 134 | + * |
|
| 135 | + * @var string $_id |
|
| 136 | + */ |
|
| 137 | + var $_id; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Current cache group |
|
| 141 | + * |
|
| 142 | + * @var string $_group |
|
| 143 | + */ |
|
| 144 | + var $_group; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Enable / Disable "Memory Caching" |
|
| 148 | + * |
|
| 149 | + * NB : There is no lifetime for memory caching ! |
|
| 150 | + * |
|
| 151 | + * @var boolean $_memoryCaching |
|
| 152 | + */ |
|
| 153 | + var $_memoryCaching = false; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Enable / Disable "Only Memory Caching" |
|
| 157 | + * (be carefull, memory caching is "beta quality") |
|
| 158 | + * |
|
| 159 | + * @var boolean $_onlyMemoryCaching |
|
| 160 | + */ |
|
| 161 | + var $_onlyMemoryCaching = false; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Memory caching array |
|
| 165 | + * |
|
| 166 | + * @var array $_memoryCachingArray |
|
| 167 | + */ |
|
| 168 | + var $_memoryCachingArray = array(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Memory caching counter |
|
| 172 | + * |
|
| 173 | + * @var int $memoryCachingCounter |
|
| 174 | + */ |
|
| 175 | + var $_memoryCachingCounter = 0; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Memory caching limit |
|
| 179 | + * |
|
| 180 | + * @var int $memoryCachingLimit |
|
| 181 | + */ |
|
| 182 | + var $_memoryCachingLimit = 1000; |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * File Name protection |
|
| 186 | + * |
|
| 187 | + * if set to true, you can use any cache id or group name |
|
| 188 | + * if set to false, it can be faster but cache ids and group names |
|
| 189 | + * will be used directly in cache file names so be carefull with |
|
| 190 | + * special characters... |
|
| 191 | + * |
|
| 192 | + * @var boolean $fileNameProtection |
|
| 193 | + */ |
|
| 194 | + var $_fileNameProtection = true; |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Enable / disable automatic serialization |
|
| 198 | + * |
|
| 199 | + * it can be used to save directly datas which aren't strings |
|
| 200 | + * (but it's slower) |
|
| 201 | + * |
|
| 202 | + * @var boolean $_serialize |
|
| 203 | + */ |
|
| 204 | + var $_automaticSerialization = false; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Disable / Tune the automatic cleaning process |
|
| 208 | + * |
|
| 209 | + * The automatic cleaning process destroy too old (for the given life time) |
|
| 210 | + * cache files when a new cache file is written. |
|
| 211 | + * 0 => no automatic cache cleaning |
|
| 212 | + * 1 => systematic cache cleaning |
|
| 213 | + * x (integer) > 1 => automatic cleaning randomly 1 times on x cache write |
|
| 214 | + * |
|
| 215 | + * @var int $_automaticCleaning |
|
| 216 | + */ |
|
| 217 | + var $_automaticCleaningFactor = 0; |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Nested directory level |
|
| 221 | + * |
|
| 222 | + * Set the hashed directory structure level. 0 means "no hashed directory |
|
| 223 | + * structure", 1 means "one level of directory", 2 means "two levels"... |
|
| 224 | + * This option can speed up Cache_Lite only when you have many thousands of |
|
| 225 | + * cache file. Only specific benchs can help you to choose the perfect value |
|
| 226 | + * for you. Maybe, 1 or 2 is a good start. |
|
| 227 | + * |
|
| 228 | + * @var int $_hashedDirectoryLevel |
|
| 229 | + */ |
|
| 230 | + var $_hashedDirectoryLevel = 0; |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Umask for hashed directory structure |
|
| 234 | + * |
|
| 235 | + * @var int $_hashedDirectoryUmask |
|
| 236 | + */ |
|
| 237 | + var $_hashedDirectoryUmask = 0770; |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * API break for error handling in CACHE_LITE_ERROR_RETURN mode |
|
| 241 | + * |
|
| 242 | + * In CACHE_LITE_ERROR_RETURN mode, error handling was not good because |
|
| 243 | + * for example save() method always returned a boolean (a PEAR_Error object |
|
| 244 | + * would be better in CACHE_LITE_ERROR_RETURN mode). To correct this without |
|
| 245 | + * breaking the API, this option (false by default) can change this handling. |
|
| 246 | + * |
|
| 247 | + * @var boolean |
|
| 248 | + */ |
|
| 249 | + var $_errorHandlingAPIBreak = false; |
|
| 250 | + |
|
| 251 | + // --- Public methods --- |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Constructor |
|
| 255 | + * |
|
| 256 | + * $options is an assoc. Available options are : |
|
| 257 | + * $options = array( |
|
| 258 | + * 'cacheDir' => directory where to put the cache files (string), |
|
| 259 | + * 'caching' => enable / disable caching (boolean), |
|
| 260 | + * 'lifeTime' => cache lifetime in seconds (int), |
|
| 261 | + * 'fileLocking' => enable / disable fileLocking (boolean), |
|
| 262 | + * 'writeControl' => enable / disable write control (boolean), |
|
| 263 | + * 'readControl' => enable / disable read control (boolean), |
|
| 264 | + * 'readControlType' => type of read control 'crc32', 'md5', 'strlen' (string), |
|
| 265 | + * 'pearErrorMode' => pear error mode (when raiseError is called) (cf PEAR doc) (int), |
|
| 266 | + * 'memoryCaching' => enable / disable memory caching (boolean), |
|
| 267 | + * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
| 268 | + * 'memoryCachingLimit' => max nbr of records to store into memory caching (int), |
|
| 269 | + * 'fileNameProtection' => enable / disable automatic file name protection (boolean), |
|
| 270 | + * 'automaticSerialization' => enable / disable automatic serialization (boolean), |
|
| 271 | + * 'automaticCleaningFactor' => distable / tune automatic cleaning process (int), |
|
| 272 | + * 'hashedDirectoryLevel' => level of the hashed directory system (int), |
|
| 273 | + * 'hashedDirectoryUmask' => umask for hashed directory structure (int), |
|
| 274 | + * 'errorHandlingAPIBreak' => API break for better error handling ? (boolean) |
|
| 275 | + * ); |
|
| 276 | + * |
|
| 277 | + * @param array $options options |
|
| 278 | + * @access public |
|
| 279 | + */ |
|
| 280 | + function __construct($options = array(NULL)) |
|
| 281 | + { |
|
| 282 | + foreach($options as $key => $value) { |
|
| 283 | + $this->setOption($key, $value); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Generic way to set a Cache_Lite option |
|
| 289 | + * |
|
| 290 | + * see Cache_Lite constructor for available options |
|
| 291 | + * |
|
| 292 | + * @var string $name name of the option |
|
| 293 | + * @var mixed $value value of the option |
|
| 294 | + * @access public |
|
| 295 | + */ |
|
| 296 | + function setOption($name, $value) |
|
| 297 | + { |
|
| 298 | + $availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode'); |
|
| 299 | + if (in_array($name, $availableOptions)) { |
|
| 300 | + $property = '_'.$name; |
|
| 301 | + $this->$property = $value; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Test if a cache is available and (if yes) return it |
|
| 307 | + * |
|
| 308 | + * @param string $id cache id |
|
| 309 | + * @param string $group name of the cache group |
|
| 310 | + * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 311 | + * @return string data of the cache (else : false) |
|
| 312 | + * @access public |
|
| 313 | + */ |
|
| 314 | + function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 315 | + { |
|
| 316 | + $this->_id = $id; |
|
| 317 | + $this->_group = $group; |
|
| 318 | + $data = false; |
|
| 319 | + if ($this->_caching) { |
|
| 320 | + $this->_setRefreshTime(); |
|
| 321 | + $this->_setFileName($id, $group); |
|
| 322 | + clearstatcache(); |
|
| 323 | + if ($this->_memoryCaching) { |
|
| 324 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 325 | + if ($this->_automaticSerialization) { |
|
| 326 | + return unserialize($this->_memoryCachingArray[$this->_file]); |
|
| 327 | + } |
|
| 328 | + return $this->_memoryCachingArray[$this->_file]; |
|
| 329 | + } |
|
| 330 | + if ($this->_onlyMemoryCaching) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + if (($doNotTestCacheValidity) || (is_null($this->_refreshTime))) { |
|
| 335 | + if (file_exists($this->_file)) { |
|
| 336 | + $data = $this->_read(); |
|
| 337 | + } |
|
| 338 | + } else { |
|
| 339 | + if ((file_exists($this->_file)) && (@filemtime($this->_file) > $this->_refreshTime)) { |
|
| 340 | + $data = $this->_read(); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + if (($data) and ($this->_memoryCaching)) { |
|
| 344 | + $this->_memoryCacheAdd($data); |
|
| 345 | + } |
|
| 346 | + if (($this->_automaticSerialization) and (is_string($data))) { |
|
| 347 | + $data = unserialize($data); |
|
| 348 | + } |
|
| 349 | + return $data; |
|
| 350 | + } |
|
| 351 | + return false; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Save some data in a cache file |
|
| 356 | + * |
|
| 357 | + * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 358 | + * @param string $id cache id |
|
| 359 | + * @param string $group name of the cache group |
|
| 360 | + * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 361 | + * @access public |
|
| 362 | + */ |
|
| 363 | + function save($data, $id = NULL, $group = 'default') |
|
| 364 | + { |
|
| 365 | + if ($this->_caching) { |
|
| 366 | + if ($this->_automaticSerialization) { |
|
| 367 | + $data = serialize($data); |
|
| 368 | + } |
|
| 369 | + if (isset($id)) { |
|
| 370 | + $this->_setFileName($id, $group); |
|
| 371 | + } |
|
| 372 | + if ($this->_memoryCaching) { |
|
| 373 | + $this->_memoryCacheAdd($data); |
|
| 374 | + if ($this->_onlyMemoryCaching) { |
|
| 375 | + return true; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + if ($this->_automaticCleaningFactor>0) { |
|
| 379 | + $rand = rand(1, $this->_automaticCleaningFactor); |
|
| 380 | + if ($rand==1) { |
|
| 381 | + $this->clean(false, 'old'); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + if ($this->_writeControl) { |
|
| 385 | + $res = $this->_writeAndControl($data); |
|
| 386 | + if (is_bool($res)) { |
|
| 387 | + if ($res) { |
|
| 388 | + return true; |
|
| 389 | + } |
|
| 390 | + // if $res if false, we need to invalidate the cache |
|
| 391 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 392 | + return false; |
|
| 393 | + } |
|
| 394 | + } else { |
|
| 395 | + $res = $this->_write($data); |
|
| 396 | + } |
|
| 397 | + if (is_object($res)) { |
|
| 398 | + // $res is a PEAR_Error object |
|
| 399 | + if (!($this->_errorHandlingAPIBreak)) { |
|
| 400 | + return false; // we return false (old API) |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + return $res; |
|
| 404 | + } |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Remove a cache file |
|
| 410 | + * |
|
| 411 | + * @param string $id cache id |
|
| 412 | + * @param string $group name of the cache group |
|
| 413 | + * @return boolean true if no problem |
|
| 414 | + * @access public |
|
| 415 | + */ |
|
| 416 | + function remove($id, $group = 'default') |
|
| 417 | + { |
|
| 418 | + $this->_setFileName($id, $group); |
|
| 419 | + if ($this->_memoryCaching) { |
|
| 420 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 421 | + unset($this->_memoryCachingArray[$this->_file]); |
|
| 422 | + $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1; |
|
| 423 | + } |
|
| 424 | + if ($this->_onlyMemoryCaching) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + return $this->_unlink($this->_file); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Clean the cache |
|
| 433 | + * |
|
| 434 | + * if no group is specified all cache files will be destroyed |
|
| 435 | + * else only cache files of the specified group will be destroyed |
|
| 436 | + * |
|
| 437 | + * @param string $group name of the cache group |
|
| 438 | + * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 439 | + * 'callback_myFunction' |
|
| 440 | + * @return boolean true if no problem |
|
| 441 | + * @access public |
|
| 442 | + */ |
|
| 443 | + function clean($group = false, $mode = 'ingroup') |
|
| 444 | + { |
|
| 445 | + return $this->_cleanDir($this->_cacheDir, $group, $mode); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Set to debug mode |
|
| 450 | + * |
|
| 451 | + * When an error is found, the script will stop and the message will be displayed |
|
| 452 | + * (in debug mode only). |
|
| 453 | + * |
|
| 454 | + * @access public |
|
| 455 | + */ |
|
| 456 | + function setToDebug() |
|
| 457 | + { |
|
| 458 | + $this->setOption('pearErrorMode', CACHE_LITE_ERROR_DIE); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Set a new life time |
|
| 463 | + * |
|
| 464 | + * @param int $newLifeTime new life time (in seconds) |
|
| 465 | + * @access public |
|
| 466 | + */ |
|
| 467 | + function setLifeTime($newLifeTime) |
|
| 468 | + { |
|
| 469 | + $this->_lifeTime = $newLifeTime; |
|
| 470 | + $this->_setRefreshTime(); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Save the state of the caching memory array into a cache file cache |
|
| 475 | + * |
|
| 476 | + * @param string $id cache id |
|
| 477 | + * @param string $group name of the cache group |
|
| 478 | + * @access public |
|
| 479 | + */ |
|
| 480 | + function saveMemoryCachingState($id, $group = 'default') |
|
| 481 | + { |
|
| 482 | + if ($this->_caching) { |
|
| 483 | + $array = array( |
|
| 484 | + 'counter' => $this->_memoryCachingCounter, |
|
| 485 | + 'array' => $this->_memoryCachingState |
|
| 486 | + ); |
|
| 487 | + $data = serialize($array); |
|
| 488 | + $this->save($data, $id, $group); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Load the state of the caching memory array from a given cache file cache |
|
| 494 | + * |
|
| 495 | + * @param string $id cache id |
|
| 496 | + * @param string $group name of the cache group |
|
| 497 | + * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 498 | + * @access public |
|
| 499 | + */ |
|
| 500 | + function getMemoryCachingState($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 501 | + { |
|
| 502 | + if ($this->_caching) { |
|
| 503 | + if ($data = $this->get($id, $group, $doNotTestCacheValidity)) { |
|
| 504 | + $array = unserialize($data); |
|
| 505 | + $this->_memoryCachingCounter = $array['counter']; |
|
| 506 | + $this->_memoryCachingArray = $array['array']; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Return the cache last modification time |
|
| 513 | + * |
|
| 514 | + * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 515 | + * |
|
| 516 | + * @return int last modification time |
|
| 517 | + */ |
|
| 518 | + function lastModified() |
|
| 519 | + { |
|
| 520 | + return @filemtime($this->_file); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Trigger error |
|
| 525 | + * |
|
| 526 | + * @param string $msg error message |
|
| 527 | + * @param int $code error code |
|
| 528 | + * @access public |
|
| 529 | + */ |
|
| 530 | + function raiseError($msg, $code) |
|
| 531 | + { |
|
| 532 | + return new Exception($msg); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Extend the life of a valid cache file |
|
| 537 | + * |
|
| 538 | + * see http://pear.php.net/bugs/bug.php?id=6681 |
|
| 539 | + * |
|
| 540 | + * @access public |
|
| 541 | + */ |
|
| 542 | + function extendLife() |
|
| 543 | + { |
|
| 544 | + @touch($this->_file); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // --- Private methods --- |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Compute & set the refresh time |
|
| 551 | + * |
|
| 552 | + * @access private |
|
| 553 | + */ |
|
| 554 | + function _setRefreshTime() |
|
| 555 | + { |
|
| 556 | + if (is_null($this->_lifeTime)) { |
|
| 557 | + $this->_refreshTime = null; |
|
| 558 | + } else { |
|
| 559 | + $this->_refreshTime = time() - $this->_lifeTime; |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Remove a file |
|
| 565 | + * |
|
| 566 | + * @param string $file complete file path and name |
|
| 567 | + * @return boolean true if no problem |
|
| 568 | + * @access private |
|
| 569 | + */ |
|
| 570 | + function _unlink($file) |
|
| 571 | + { |
|
| 572 | + if (!@unlink($file)) { |
|
| 573 | + return $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 574 | + } |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Recursive function for cleaning cache file in the given directory |
|
| 580 | + * |
|
| 581 | + * @param string $dir directory complete path (with a trailing slash) |
|
| 582 | + * @param string $group name of the cache group |
|
| 583 | + * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 584 | 584 | 'callback_myFunction' |
| 585 | - * @return boolean true if no problem |
|
| 586 | - * @access private |
|
| 587 | - */ |
|
| 588 | - function _cleanDir($dir, $group = false, $mode = 'ingroup') |
|
| 589 | - { |
|
| 590 | - if ($this->_fileNameProtection) { |
|
| 591 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 592 | - } else { |
|
| 593 | - $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 594 | - } |
|
| 595 | - if ($this->_memoryCaching) { |
|
| 596 | - while (list($key, ) = each($this->_memoryCachingArray)) { |
|
| 597 | - if (strpos($key, $motif, 0)) { |
|
| 598 | - unset($this->_memoryCachingArray[$key]); |
|
| 599 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1; |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - if ($this->_onlyMemoryCaching) { |
|
| 603 | - return true; |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - if (!($dh = opendir($dir))) { |
|
| 607 | - return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4); |
|
| 608 | - } |
|
| 609 | - $result = true; |
|
| 610 | - while ($file = readdir($dh)) { |
|
| 611 | - if (($file != '.') && ($file != '..')) { |
|
| 612 | - if (substr($file, 0, 6)=='cache_') { |
|
| 613 | - $file2 = $dir . $file; |
|
| 614 | - if (is_file($file2)) { |
|
| 615 | - switch (substr($mode, 0, 9)) { |
|
| 616 | - case 'old': |
|
| 617 | - // files older than lifeTime get deleted from cache |
|
| 618 | - if (!is_null($this->_lifeTime)) { |
|
| 619 | - if ((time() - @filemtime($file2)) > $this->_lifeTime) { |
|
| 620 | - $result = ($result and ($this->_unlink($file2))); |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - break; |
|
| 624 | - case 'notingroup': |
|
| 625 | - if (!strpos($file2, $motif, 0)) { |
|
| 626 | - $result = ($result and ($this->_unlink($file2))); |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - case 'callback_': |
|
| 630 | - $func = substr($mode, 9, strlen($mode) - 9); |
|
| 631 | - if ($func($file2, $group)) { |
|
| 632 | - $result = ($result and ($this->_unlink($file2))); |
|
| 633 | - } |
|
| 634 | - break; |
|
| 635 | - case 'ingroup': |
|
| 636 | - default: |
|
| 637 | - if (strpos($file2, $motif, 0)) { |
|
| 638 | - $result = ($result and ($this->_unlink($file2))); |
|
| 639 | - } |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if ((is_dir($file2)) and ($this->_hashedDirectoryLevel>0)) { |
|
| 644 | - $result = ($result and ($this->_cleanDir($file2 . '/', $group, $mode))); |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - return $result; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Add some date in the memory caching array |
|
| 654 | - * |
|
| 655 | - * @param string $data data to cache |
|
| 656 | - * @access private |
|
| 657 | - */ |
|
| 658 | - function _memoryCacheAdd($data) |
|
| 659 | - { |
|
| 660 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
| 661 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 662 | - list($key, ) = each($this->_memoryCachingArray); |
|
| 663 | - unset($this->_memoryCachingArray[$key]); |
|
| 664 | - } else { |
|
| 665 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * Make a file name (with path) |
|
| 671 | - * |
|
| 672 | - * @param string $id cache id |
|
| 673 | - * @param string $group name of the group |
|
| 674 | - * @access private |
|
| 675 | - */ |
|
| 676 | - function _setFileName($id, $group) |
|
| 677 | - { |
|
| 678 | - if ($this->_fileNameProtection) { |
|
| 679 | - $suffix = 'cache_'.md5($group).'_'.md5($id); |
|
| 680 | - } else { |
|
| 681 | - $suffix = 'cache_'.$group.'_'.$id; |
|
| 682 | - } |
|
| 683 | - $root = $this->_cacheDir; |
|
| 684 | - if ($this->_hashedDirectoryLevel>0) { |
|
| 685 | - $hash = md5($suffix); |
|
| 686 | - for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 687 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - $this->_fileName = $suffix; |
|
| 691 | - $this->_file = $root.$suffix; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Read the cache file and return the content |
|
| 696 | - * |
|
| 697 | - * @return string content of the cache file (else : false or a PEAR_Error object) |
|
| 698 | - * @access private |
|
| 699 | - */ |
|
| 700 | - function _read() |
|
| 701 | - { |
|
| 702 | - $fp = @fopen($this->_file, "rb"); |
|
| 703 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 704 | - if ($fp) { |
|
| 705 | - clearstatcache(); |
|
| 706 | - $length = @filesize($this->_file); |
|
| 707 | - // $mqr = get_magic_quotes_runtime(); |
|
| 708 | - // set_magic_quotes_runtime(0); |
|
| 709 | - if ($this->_readControl) { |
|
| 710 | - $hashControl = @fread($fp, 32); |
|
| 711 | - $length = $length - 32; |
|
| 712 | - } |
|
| 713 | - if ($length) { |
|
| 714 | - $data = @fread($fp, $length); |
|
| 715 | - } else { |
|
| 716 | - $data = ''; |
|
| 717 | - } |
|
| 718 | - // set_magic_quotes_runtime($mqr); |
|
| 719 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 720 | - @fclose($fp); |
|
| 721 | - if ($this->_readControl) { |
|
| 722 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
| 723 | - if ($hashData != $hashControl) { |
|
| 724 | - if (!(is_null($this->_lifeTime))) { |
|
| 725 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 726 | - } else { |
|
| 727 | - @unlink($this->_file); |
|
| 728 | - } |
|
| 729 | - return false; |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - return $data; |
|
| 733 | - } |
|
| 734 | - return $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Write the given data in the cache file |
|
| 739 | - * |
|
| 740 | - * @param string $data data to put in cache |
|
| 741 | - * @return boolean true if ok (a PEAR_Error object else) |
|
| 742 | - * @access private |
|
| 743 | - */ |
|
| 744 | - function _write($data) |
|
| 745 | - { |
|
| 746 | - $oldmask = umask(0); |
|
| 747 | - if ($this->_hashedDirectoryLevel > 0) { |
|
| 748 | - $hash = md5($this->_fileName); |
|
| 749 | - $root = $this->_cacheDir; |
|
| 750 | - for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 751 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 752 | - if (!(@is_dir($root))) { |
|
| 753 | - @mkdir($root, $this->_hashedDirectoryUmask); |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - $fp = @fopen($this->_file, "wb"); |
|
| 758 | - if ($fp) { |
|
| 759 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 760 | - if ($this->_readControl) { |
|
| 761 | - @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 762 | - } |
|
| 763 | - $len = strlen($data); |
|
| 764 | - @fwrite($fp, $data, $len); |
|
| 765 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 766 | - @fclose($fp); |
|
| 767 | - umask($oldmask); |
|
| 768 | - return true; |
|
| 769 | - } |
|
| 770 | - umask($oldmask); |
|
| 771 | - return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * Write the given data in the cache file and control it just after to avoir corrupted cache entries |
|
| 776 | - * |
|
| 777 | - * @param string $data data to put in cache |
|
| 778 | - * @return boolean true if the test is ok (else : false or a PEAR_Error object) |
|
| 779 | - * @access private |
|
| 780 | - */ |
|
| 781 | - function _writeAndControl($data) |
|
| 782 | - { |
|
| 783 | - $result = $this->_write($data); |
|
| 784 | - if (is_object($result)) { |
|
| 785 | - return $result; # We return the PEAR_Error object |
|
| 786 | - } |
|
| 787 | - $dataRead = $this->_read(); |
|
| 788 | - if (is_object($dataRead)) { |
|
| 789 | - return $result; # We return the PEAR_Error object |
|
| 790 | - } |
|
| 791 | - if ((is_bool($dataRead)) && (!$dataRead)) { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - return ($dataRead==$data); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * Make a control key with the string containing datas |
|
| 799 | - * |
|
| 800 | - * @param string $data data |
|
| 801 | - * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 802 | - * @return string control key |
|
| 803 | - * @access private |
|
| 804 | - */ |
|
| 805 | - function _hash($data, $controlType) |
|
| 806 | - { |
|
| 807 | - switch ($controlType) { |
|
| 808 | - case 'md5': |
|
| 809 | - return md5($data); |
|
| 810 | - case 'crc32': |
|
| 811 | - return sprintf('% 32d', crc32($data)); |
|
| 812 | - case 'strlen': |
|
| 813 | - return sprintf('% 32d', strlen($data)); |
|
| 814 | - default: |
|
| 815 | - return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 816 | - } |
|
| 817 | - } |
|
| 585 | + * @return boolean true if no problem |
|
| 586 | + * @access private |
|
| 587 | + */ |
|
| 588 | + function _cleanDir($dir, $group = false, $mode = 'ingroup') |
|
| 589 | + { |
|
| 590 | + if ($this->_fileNameProtection) { |
|
| 591 | + $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 592 | + } else { |
|
| 593 | + $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
| 594 | + } |
|
| 595 | + if ($this->_memoryCaching) { |
|
| 596 | + while (list($key, ) = each($this->_memoryCachingArray)) { |
|
| 597 | + if (strpos($key, $motif, 0)) { |
|
| 598 | + unset($this->_memoryCachingArray[$key]); |
|
| 599 | + $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1; |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + if ($this->_onlyMemoryCaching) { |
|
| 603 | + return true; |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + if (!($dh = opendir($dir))) { |
|
| 607 | + return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4); |
|
| 608 | + } |
|
| 609 | + $result = true; |
|
| 610 | + while ($file = readdir($dh)) { |
|
| 611 | + if (($file != '.') && ($file != '..')) { |
|
| 612 | + if (substr($file, 0, 6)=='cache_') { |
|
| 613 | + $file2 = $dir . $file; |
|
| 614 | + if (is_file($file2)) { |
|
| 615 | + switch (substr($mode, 0, 9)) { |
|
| 616 | + case 'old': |
|
| 617 | + // files older than lifeTime get deleted from cache |
|
| 618 | + if (!is_null($this->_lifeTime)) { |
|
| 619 | + if ((time() - @filemtime($file2)) > $this->_lifeTime) { |
|
| 620 | + $result = ($result and ($this->_unlink($file2))); |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + break; |
|
| 624 | + case 'notingroup': |
|
| 625 | + if (!strpos($file2, $motif, 0)) { |
|
| 626 | + $result = ($result and ($this->_unlink($file2))); |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + case 'callback_': |
|
| 630 | + $func = substr($mode, 9, strlen($mode) - 9); |
|
| 631 | + if ($func($file2, $group)) { |
|
| 632 | + $result = ($result and ($this->_unlink($file2))); |
|
| 633 | + } |
|
| 634 | + break; |
|
| 635 | + case 'ingroup': |
|
| 636 | + default: |
|
| 637 | + if (strpos($file2, $motif, 0)) { |
|
| 638 | + $result = ($result and ($this->_unlink($file2))); |
|
| 639 | + } |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if ((is_dir($file2)) and ($this->_hashedDirectoryLevel>0)) { |
|
| 644 | + $result = ($result and ($this->_cleanDir($file2 . '/', $group, $mode))); |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + return $result; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Add some date in the memory caching array |
|
| 654 | + * |
|
| 655 | + * @param string $data data to cache |
|
| 656 | + * @access private |
|
| 657 | + */ |
|
| 658 | + function _memoryCacheAdd($data) |
|
| 659 | + { |
|
| 660 | + $this->_memoryCachingArray[$this->_file] = $data; |
|
| 661 | + if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 662 | + list($key, ) = each($this->_memoryCachingArray); |
|
| 663 | + unset($this->_memoryCachingArray[$key]); |
|
| 664 | + } else { |
|
| 665 | + $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * Make a file name (with path) |
|
| 671 | + * |
|
| 672 | + * @param string $id cache id |
|
| 673 | + * @param string $group name of the group |
|
| 674 | + * @access private |
|
| 675 | + */ |
|
| 676 | + function _setFileName($id, $group) |
|
| 677 | + { |
|
| 678 | + if ($this->_fileNameProtection) { |
|
| 679 | + $suffix = 'cache_'.md5($group).'_'.md5($id); |
|
| 680 | + } else { |
|
| 681 | + $suffix = 'cache_'.$group.'_'.$id; |
|
| 682 | + } |
|
| 683 | + $root = $this->_cacheDir; |
|
| 684 | + if ($this->_hashedDirectoryLevel>0) { |
|
| 685 | + $hash = md5($suffix); |
|
| 686 | + for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 687 | + $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + $this->_fileName = $suffix; |
|
| 691 | + $this->_file = $root.$suffix; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Read the cache file and return the content |
|
| 696 | + * |
|
| 697 | + * @return string content of the cache file (else : false or a PEAR_Error object) |
|
| 698 | + * @access private |
|
| 699 | + */ |
|
| 700 | + function _read() |
|
| 701 | + { |
|
| 702 | + $fp = @fopen($this->_file, "rb"); |
|
| 703 | + if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
| 704 | + if ($fp) { |
|
| 705 | + clearstatcache(); |
|
| 706 | + $length = @filesize($this->_file); |
|
| 707 | + // $mqr = get_magic_quotes_runtime(); |
|
| 708 | + // set_magic_quotes_runtime(0); |
|
| 709 | + if ($this->_readControl) { |
|
| 710 | + $hashControl = @fread($fp, 32); |
|
| 711 | + $length = $length - 32; |
|
| 712 | + } |
|
| 713 | + if ($length) { |
|
| 714 | + $data = @fread($fp, $length); |
|
| 715 | + } else { |
|
| 716 | + $data = ''; |
|
| 717 | + } |
|
| 718 | + // set_magic_quotes_runtime($mqr); |
|
| 719 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 720 | + @fclose($fp); |
|
| 721 | + if ($this->_readControl) { |
|
| 722 | + $hashData = $this->_hash($data, $this->_readControlType); |
|
| 723 | + if ($hashData != $hashControl) { |
|
| 724 | + if (!(is_null($this->_lifeTime))) { |
|
| 725 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 726 | + } else { |
|
| 727 | + @unlink($this->_file); |
|
| 728 | + } |
|
| 729 | + return false; |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + return $data; |
|
| 733 | + } |
|
| 734 | + return $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Write the given data in the cache file |
|
| 739 | + * |
|
| 740 | + * @param string $data data to put in cache |
|
| 741 | + * @return boolean true if ok (a PEAR_Error object else) |
|
| 742 | + * @access private |
|
| 743 | + */ |
|
| 744 | + function _write($data) |
|
| 745 | + { |
|
| 746 | + $oldmask = umask(0); |
|
| 747 | + if ($this->_hashedDirectoryLevel > 0) { |
|
| 748 | + $hash = md5($this->_fileName); |
|
| 749 | + $root = $this->_cacheDir; |
|
| 750 | + for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 751 | + $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 752 | + if (!(@is_dir($root))) { |
|
| 753 | + @mkdir($root, $this->_hashedDirectoryUmask); |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + $fp = @fopen($this->_file, "wb"); |
|
| 758 | + if ($fp) { |
|
| 759 | + if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
| 760 | + if ($this->_readControl) { |
|
| 761 | + @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 762 | + } |
|
| 763 | + $len = strlen($data); |
|
| 764 | + @fwrite($fp, $data, $len); |
|
| 765 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
| 766 | + @fclose($fp); |
|
| 767 | + umask($oldmask); |
|
| 768 | + return true; |
|
| 769 | + } |
|
| 770 | + umask($oldmask); |
|
| 771 | + return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * Write the given data in the cache file and control it just after to avoir corrupted cache entries |
|
| 776 | + * |
|
| 777 | + * @param string $data data to put in cache |
|
| 778 | + * @return boolean true if the test is ok (else : false or a PEAR_Error object) |
|
| 779 | + * @access private |
|
| 780 | + */ |
|
| 781 | + function _writeAndControl($data) |
|
| 782 | + { |
|
| 783 | + $result = $this->_write($data); |
|
| 784 | + if (is_object($result)) { |
|
| 785 | + return $result; # We return the PEAR_Error object |
|
| 786 | + } |
|
| 787 | + $dataRead = $this->_read(); |
|
| 788 | + if (is_object($dataRead)) { |
|
| 789 | + return $result; # We return the PEAR_Error object |
|
| 790 | + } |
|
| 791 | + if ((is_bool($dataRead)) && (!$dataRead)) { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + return ($dataRead==$data); |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * Make a control key with the string containing datas |
|
| 799 | + * |
|
| 800 | + * @param string $data data |
|
| 801 | + * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 802 | + * @return string control key |
|
| 803 | + * @access private |
|
| 804 | + */ |
|
| 805 | + function _hash($data, $controlType) |
|
| 806 | + { |
|
| 807 | + switch ($controlType) { |
|
| 808 | + case 'md5': |
|
| 809 | + return md5($data); |
|
| 810 | + case 'crc32': |
|
| 811 | + return sprintf('% 32d', crc32($data)); |
|
| 812 | + case 'strlen': |
|
| 813 | + return sprintf('% 32d', strlen($data)); |
|
| 814 | + default: |
|
| 815 | + return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | 819 | } |
| 820 | 820 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | function __construct($options = array(NULL)) |
| 281 | 281 | { |
| 282 | - foreach($options as $key => $value) { |
|
| 282 | + foreach ($options as $key => $value) { |
|
| 283 | 283 | $this->setOption($key, $value); |
| 284 | 284 | } |
| 285 | 285 | } |
@@ -375,9 +375,9 @@ discard block |
||
| 375 | 375 | return true; |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | - if ($this->_automaticCleaningFactor>0) { |
|
| 378 | + if ($this->_automaticCleaningFactor > 0) { |
|
| 379 | 379 | $rand = rand(1, $this->_automaticCleaningFactor); |
| 380 | - if ($rand==1) { |
|
| 380 | + if ($rand == 1) { |
|
| 381 | 381 | $this->clean(false, 'old'); |
| 382 | 382 | } |
| 383 | 383 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | return true; |
| 389 | 389 | } |
| 390 | 390 | // if $res if false, we need to invalidate the cache |
| 391 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 391 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 392 | 392 | return false; |
| 393 | 393 | } |
| 394 | 394 | } else { |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
| 594 | 594 | } |
| 595 | 595 | if ($this->_memoryCaching) { |
| 596 | - while (list($key, ) = each($this->_memoryCachingArray)) { |
|
| 596 | + while (list($key,) = each($this->_memoryCachingArray)) { |
|
| 597 | 597 | if (strpos($key, $motif, 0)) { |
| 598 | 598 | unset($this->_memoryCachingArray[$key]); |
| 599 | 599 | $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1; |
@@ -609,8 +609,8 @@ discard block |
||
| 609 | 609 | $result = true; |
| 610 | 610 | while ($file = readdir($dh)) { |
| 611 | 611 | if (($file != '.') && ($file != '..')) { |
| 612 | - if (substr($file, 0, 6)=='cache_') { |
|
| 613 | - $file2 = $dir . $file; |
|
| 612 | + if (substr($file, 0, 6) == 'cache_') { |
|
| 613 | + $file2 = $dir.$file; |
|
| 614 | 614 | if (is_file($file2)) { |
| 615 | 615 | switch (substr($mode, 0, 9)) { |
| 616 | 616 | case 'old': |
@@ -640,8 +640,8 @@ discard block |
||
| 640 | 640 | break; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - if ((is_dir($file2)) and ($this->_hashedDirectoryLevel>0)) { |
|
| 644 | - $result = ($result and ($this->_cleanDir($file2 . '/', $group, $mode))); |
|
| 643 | + if ((is_dir($file2)) and ($this->_hashedDirectoryLevel > 0)) { |
|
| 644 | + $result = ($result and ($this->_cleanDir($file2.'/', $group, $mode))); |
|
| 645 | 645 | } |
| 646 | 646 | } |
| 647 | 647 | } |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | { |
| 660 | 660 | $this->_memoryCachingArray[$this->_file] = $data; |
| 661 | 661 | if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
| 662 | - list($key, ) = each($this->_memoryCachingArray); |
|
| 662 | + list($key,) = each($this->_memoryCachingArray); |
|
| 663 | 663 | unset($this->_memoryCachingArray[$key]); |
| 664 | 664 | } else { |
| 665 | 665 | $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
@@ -681,10 +681,10 @@ discard block |
||
| 681 | 681 | $suffix = 'cache_'.$group.'_'.$id; |
| 682 | 682 | } |
| 683 | 683 | $root = $this->_cacheDir; |
| 684 | - if ($this->_hashedDirectoryLevel>0) { |
|
| 684 | + if ($this->_hashedDirectoryLevel > 0) { |
|
| 685 | 685 | $hash = md5($suffix); |
| 686 | - for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 687 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 686 | + for ($i = 0; $i < $this->_hashedDirectoryLevel; $i++) { |
|
| 687 | + $root = $root.'cache_'.substr($hash, 0, $i + 1).'/'; |
|
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | $this->_fileName = $suffix; |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | $hashData = $this->_hash($data, $this->_readControlType); |
| 723 | 723 | if ($hashData != $hashControl) { |
| 724 | 724 | if (!(is_null($this->_lifeTime))) { |
| 725 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
| 725 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 726 | 726 | } else { |
| 727 | 727 | @unlink($this->_file); |
| 728 | 728 | } |
@@ -747,8 +747,8 @@ discard block |
||
| 747 | 747 | if ($this->_hashedDirectoryLevel > 0) { |
| 748 | 748 | $hash = md5($this->_fileName); |
| 749 | 749 | $root = $this->_cacheDir; |
| 750 | - for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { |
|
| 751 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 750 | + for ($i = 0; $i < $this->_hashedDirectoryLevel; $i++) { |
|
| 751 | + $root = $root.'cache_'.substr($hash, 0, $i + 1).'/'; |
|
| 752 | 752 | if (!(@is_dir($root))) { |
| 753 | 753 | @mkdir($root, $this->_hashedDirectoryUmask); |
| 754 | 754 | } |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | if ((is_bool($dataRead)) && (!$dataRead)) { |
| 792 | 792 | return false; |
| 793 | 793 | } |
| 794 | - return ($dataRead==$data); |
|
| 794 | + return ($dataRead == $data); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | /** |
@@ -21,77 +21,77 @@ |
||
| 21 | 21 | { |
| 22 | 22 | var $_bufferedLifetime; |
| 23 | 23 | |
| 24 | - // --- Public methods ---- |
|
| 24 | + // --- Public methods ---- |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor |
|
| 28 | - * |
|
| 29 | - * $options is an assoc. To have a look at availables options, |
|
| 30 | - * see the constructor of the Cache_Lite class in 'Cache_Lite.php' |
|
| 31 | - * |
|
| 32 | - * @param array $options options |
|
| 33 | - * @access public |
|
| 34 | - */ |
|
| 35 | - function __construct($options = array(NULL)) |
|
| 36 | - { |
|
| 37 | - parent::__construct($options); |
|
| 38 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor |
|
| 28 | + * |
|
| 29 | + * $options is an assoc. To have a look at availables options, |
|
| 30 | + * see the constructor of the Cache_Lite class in 'Cache_Lite.php' |
|
| 31 | + * |
|
| 32 | + * @param array $options options |
|
| 33 | + * @access public |
|
| 34 | + */ |
|
| 35 | + function __construct($options = array(NULL)) |
|
| 36 | + { |
|
| 37 | + parent::__construct($options); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Save some data in a cache file |
|
| 42 | - * |
|
| 43 | - * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 44 | - * @param string $id cache id |
|
| 45 | - * @param string $group name of the cache group |
|
| 46 | - * @param int $lifetime The time in seconds that this entry should live. Defaults to the lifetime |
|
| 47 | - * set by the constructor. |
|
| 48 | - * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 49 | - * @access public |
|
| 50 | - */ |
|
| 51 | - function save($data, $id = NULL, $group = 'default', $lifetime = null) |
|
| 52 | - { |
|
| 53 | - $res = parent::save($data, $id, $group); |
|
| 54 | - if ($res === true) { |
|
| 55 | - if ($lifetime == null) { |
|
| 56 | - $lifetime = $this->_bufferedLifetime; |
|
| 57 | - } |
|
| 58 | - if ($lifetime == null) { |
|
| 59 | - $lifetime = $this->_lifeTime; |
|
| 60 | - } |
|
| 61 | - $res = $this->_setLastModified(time() + $lifetime); |
|
| 62 | - if (is_object($res)) { |
|
| 63 | - // $res is a PEAR_Error object |
|
| 64 | - if (!($this->_errorHandlingAPIBreak)) { |
|
| 65 | - return false; // we return false (old API) |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - return $res; |
|
| 70 | - } |
|
| 40 | + /** |
|
| 41 | + * Save some data in a cache file |
|
| 42 | + * |
|
| 43 | + * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 44 | + * @param string $id cache id |
|
| 45 | + * @param string $group name of the cache group |
|
| 46 | + * @param int $lifetime The time in seconds that this entry should live. Defaults to the lifetime |
|
| 47 | + * set by the constructor. |
|
| 48 | + * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 49 | + * @access public |
|
| 50 | + */ |
|
| 51 | + function save($data, $id = NULL, $group = 'default', $lifetime = null) |
|
| 52 | + { |
|
| 53 | + $res = parent::save($data, $id, $group); |
|
| 54 | + if ($res === true) { |
|
| 55 | + if ($lifetime == null) { |
|
| 56 | + $lifetime = $this->_bufferedLifetime; |
|
| 57 | + } |
|
| 58 | + if ($lifetime == null) { |
|
| 59 | + $lifetime = $this->_lifeTime; |
|
| 60 | + } |
|
| 61 | + $res = $this->_setLastModified(time() + $lifetime); |
|
| 62 | + if (is_object($res)) { |
|
| 63 | + // $res is a PEAR_Error object |
|
| 64 | + if (!($this->_errorHandlingAPIBreak)) { |
|
| 65 | + return false; // we return false (old API) |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + return $res; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Sets the ctime/mtime status for a file for the given time. |
|
| 74 | - * |
|
| 75 | - * @param integer $time Unix timestamp |
|
| 76 | - * @return boolean |
|
| 77 | - */ |
|
| 78 | - function _setLastModified($time) { |
|
| 79 | - if (@touch($this->_file, $time, $time) === false) { |
|
| 72 | + /** |
|
| 73 | + * Sets the ctime/mtime status for a file for the given time. |
|
| 74 | + * |
|
| 75 | + * @param integer $time Unix timestamp |
|
| 76 | + * @return boolean |
|
| 77 | + */ |
|
| 78 | + function _setLastModified($time) { |
|
| 79 | + if (@touch($this->_file, $time, $time) === false) { |
|
| 80 | 80 | return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1); |
| 81 | - } |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 81 | + } |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Override refresh time function. Returns current time. |
|
| 87 | - * |
|
| 88 | - */ |
|
| 89 | - function _setRefreshTime() { |
|
| 90 | - if (is_null($this->_lifeTime)) { |
|
| 91 | - $this->_refreshTime = null; |
|
| 92 | - } else { |
|
| 93 | - $this->_refreshTime = time(); |
|
| 94 | - } |
|
| 95 | - } |
|
| 85 | + /** |
|
| 86 | + * Override refresh time function. Returns current time. |
|
| 87 | + * |
|
| 88 | + */ |
|
| 89 | + function _setRefreshTime() { |
|
| 90 | + if (is_null($this->_lifeTime)) { |
|
| 91 | + $this->_refreshTime = null; |
|
| 92 | + } else { |
|
| 93 | + $this->_refreshTime = time(); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
@@ -84,7 +84,7 @@ |
||
| 84 | 84 | * @codeCoverageIgnore |
| 85 | 85 | */ |
| 86 | 86 | protected function hashKey(CacheKey $k) { |
| 87 | - return $k->getBase() . $k->getId() . serialize($k->getSub()); |
|
| 87 | + return $k->getBase().$k->getId().serialize($k->getSub()); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |