Author Topic: Cache system  (Read 2226 times)

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Cache system
« on: July 23, 2010, 10:24:40 PM »
I've done a little cache system for my website in the template index.php, it work in a way that it takes ~25% less time for my server to send the html...
but i'd like a true cache system on WSB.

here's what i've done :
in my index.php
at the absolute beginining of the file (before ANYTHING)
Code: [Select]
<?php
// Include the WB functions file
require_once(WB_PATH.&#39;/framework/functions.php&#39;);
if(file_exists(WB_PATH.&#39;/temp/&#39;.page_filename($_SERVER[&#39;REQUEST_URI&#39;]).&#39;.tmp&#39;) &&
filemtime(WB_PATH.&#39;/temp/&#39;.page_filename($_SERVER[&#39;REQUEST_URI&#39;]).&#39;.tmp&#39;) >= (time()-86400)) {
#header(&#39;HTTP/1.1 304 Not Modified&#39;);
exit(file_get_contents(WB_PATH.&#39;/temp/&#39;.page_filename($_SERVER[&#39;REQUEST_URI&#39;]).&#39;.tmp&#39;));
} else {
ob_start(&#39;cache_temp&#39;);
?>
and not at the absolute end :
Code: [Select]
<?php 
ob_end_flush
();
}
function 
cache_temp($buffer) {
file_put_contents(WB_PATH.&#39;/temp/&#39;.page_filename($_SERVER[&#39;REQUEST_URI&#39;]).&#39;.tmp&#39;,$buffer);
return $buffer;
}
?>

it's a 24h cache, cause my site dont change that much, but you can play with it by changing the "86400" to something else like :
6 hours = 21600
1 hour = 3600
10 min : 600
Xagone Inc. (formerly VotreEspace)
http://xagone.com/

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Re: Cache system
« Reply #1 on: July 26, 2010, 08:33:20 PM »
so many ppl tried to hack my cache, so funny!
Xagone Inc. (formerly VotreEspace)
http://xagone.com/

 

postern-length