Created
March 19, 2013 22:45
-
-
Save Pross/5200848 to your computer and use it in GitHub Desktop.
Simple file cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Cache { | |
function __construct( $format = '' ) { | |
$this->format = $format; | |
$this->cache_life = '1200'; | |
$this->cache_file = 'cache/' . md5( $_SERVER['REQUEST_URI'] );; | |
// check exists.... | |
$this->get_cache(); | |
} | |
function put_cache( $data ) { | |
file_put_contents( $this->cache_file, $data ); | |
$this->do_output( $data ); | |
} | |
function get_cache() { | |
$filemtime = @filemtime( $this->cache_file ); | |
if ( $filemtime && ( time() - $filemtime < $this->cache_life ) ) { | |
$this->do_output( file_get_contents( $this->cache_file ) ); | |
die(); | |
} | |
@unlink( $this->cache_file ); | |
} | |
function do_output ( $data ) { | |
header('Cache-Control: no-cache, must-revalidate'); | |
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | |
header('Content-type: application/json'); | |
echo $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment