Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 07:50:45 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155534 Posts in 21713 Topics by 7737 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Cache system  (Read 735 times)
Xagone
AddOn Development
*
Offline Offline

Posts: 478



WWW
« on: July 23, 2010, 09: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:
<?php
// Include the WB functions file
require_once(WB_PATH.'/framework/functions.php');
if(
file_exists(WB_PATH.'/temp/'.page_filename($_SERVER['REQUEST_URI']).'.tmp') &&
filemtime(WB_PATH.'/temp/'.page_filename($_SERVER['REQUEST_URI']).'.tmp') >= (time()-86400)) {
#header('HTTP/1.1 304 Not Modified');
exit(file_get_contents(WB_PATH.'/temp/'.page_filename($_SERVER['REQUEST_URI']).'.tmp'));
} else {
ob_start('cache_temp');
?>
and not at the absolute end :
Code:
<?php 
ob_end_flush
();
}
function 
cache_temp($buffer) {
file_put_contents(WB_PATH.'/temp/'.page_filename($_SERVER['REQUEST_URI']).'.tmp',$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
Logged

Xagone Inc. (formerly VotreEspace)
http://www.xagone.com/
Xagone
AddOn Development
*
Offline Offline

Posts: 478



WWW
« Reply #1 on: July 26, 2010, 07:33:20 PM »

so many ppl tried to hack my cache, so funny!
Logged

Xagone Inc. (formerly VotreEspace)
http://www.xagone.com/
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!