Skip to content

Instantly share code, notes, and snippets.

@CNG
Created April 2, 2012 21:39
Show Gist options
  • Save CNG/2287416 to your computer and use it in GitHub Desktop.
Save CNG/2287416 to your computer and use it in GitHub Desktop.
PHP cache companion file
<?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