Created
          April 14, 2013 23:56 
        
      - 
      
 - 
        
Save jcutrell/5384766 to your computer and use it in GitHub Desktop.  
    Simple PHP caching function
  
        
  
    
      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 | |
| $handle = opendir('_cache/'); | |
| while (false !== ($entry = readdir($handle))) { | |
| if (strlen($entry) > 2){ | |
| $a = explode(".", $entry); | |
| $a = explode("_", $a[0]); | |
| $tstamp = intval($a[1]); | |
| $t = time(); | |
| if ($t > ($tstamp + 12)){ | |
| // do the call, rewrite the timestamp | |
| rename("_cache/" . $entry, "_cache/file_" . $t . ".cache"); | |
| echo file_get_contents("_cache/file_" . $t . ".cache"); | |
| } else { | |
| echo file_get_contents("_cache/" . $entry); | |
| } | |
| } | |
| } | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This relies on a pre-existing
_cachefolder andfile_xxxx.cachefile. The check for the strlen of$entryis to prevent . or .. from being considered cache files. Only intended for one cache file, one call, etc.