Changeset 1289
- Timestamp:
- 03/09/10 14:09:29 (3 years ago)
- Location:
- branches/1.2
- Files:
-
- 2 edited
-
Hotaru.php (modified) (1 diff)
-
libs/Caching.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/Hotaru.php
r1286 r1289 1477 1477 1478 1478 1479 /** 1480 * Cache HTML without checking for database updates 1481 * 1482 * This function caches blocks of HTML code 1483 * 1484 * @param int $timeout timeout in minutes before cache file is deleted 1485 * @param string $html block of HTML to cache 1486 * @param string $label name to identify the cached file 1487 * @return bool 1488 */ 1489 public function cacheHTML($timeout = 0, $html = '', $label = '') 1490 { 1491 require_once(LIBS . 'Caching.php'); 1492 $caching = new Caching(); 1493 return $caching->cacheHTML($this, $timeout, $html, $label); 1494 } 1495 1496 1479 1497 /* ************************************************************* 1480 1498 * -
branches/1.2/libs/Caching.php
r1270 r1289 245 245 return $last_update; 246 246 } 247 248 249 /** 250 * Cache HTML without checking for database updates 251 * 252 * This function caches blocks of HTML code 253 * 254 * @param int $timeout timeout in minutes before cache file is deleted 255 * @param string $html block of HTML to cache 256 * @param string $label name to identify the cached file 257 * @return bool 258 */ 259 public function cacheHTML($h, $timeout = 0, $html = '', $label = '') 260 { 261 if (!$timeout || (HTML_CACHE_ON != 'true') || !$label) { return false; } 262 263 $cache_length = $timeout*60; // seconds 264 $cache = CACHE . 'html_cache/'; 265 $file = $cache . $label . ".cache"; 266 267 if (!$html) { 268 // we only want to read the cache if it exists, hence no $html passed to this function 269 if (file_exists($file)) { 270 $content = file_get_contents($file); 271 $last_modified = filemtime($file); 272 //echo "last modified: " . $last_modified . "<br />"; 273 if ($last_modified <= (time() - $cache_length)) { 274 // delete cache 275 unlink($file); 276 return false; 277 } else { 278 return $content; // return the HTML to display 279 } 280 } else { 281 return false; 282 } 283 } 284 285 // if we're here, we need to make or rewrite the cache 286 287 $fp = fopen($file, "w"); 288 289 if (flock($fp, LOCK_EX)) { // do an exclusive lock 290 ftruncate($fp, 0); // truncate file 291 fwrite($fp, $html); // write HTML 292 flock($fp, LOCK_UN); // release the lock 293 } else { 294 echo "Couldn't get the lock for the HTML cache!"; 295 } 296 297 fclose($fp); 298 return true; // the calling function already has the HTML to output 299 } 247 300 } 248 301 ?>
Note: See TracChangeset
for help on using the changeset viewer.