Created
April 2, 2012 21:39
-
-
Save CNG/2287416 to your computer and use it in GitHub Desktop.
PHP cache companion file
This file contains hidden or 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 | |
$max_age_seconds = 60*10; | |
$json_file = dirname(__FILE__).'/'.pathinfo(__FILE__,PATHINFO_FILENAME).'.json'; | |
$data; | |
if( file_exists( $json_file ) && time() - filemtime( $json_file ) < $max_age_seconds ) { | |
$data = file_get_contents( $json_file ); | |
} else { | |
// Create $data | |
$data = ''; | |
file_put_contents( $json_file, $data ); | |
} | |
$json_decoded = json_decode( $data, true ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment