Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Used to invalidate cache by three URIs and a timestamp
- *
- * Cache invalidation only happens after a certain predefined time has passed
- * Two times are set, one for normal slow data, another for faster data (live)
- * These are defined as constants CACHE_VALID and CACHE_VALID_LIVE
- * The timestamp of the files on disk is used to check when last the files were written
- * and then invalidated if that time is longer than set time
- *
- * @one (string) first URI, default "default"
- * @two (string) second URI, default "index"
- * @three (string) third URI, default "index"
- * @valid (int) valid time in minutes
- * @return (null)
- */
- function invalidate_cache($one = 'default', $two = 'index', $three = 'index', $valid = CACHE_VALID) {
- //Check if dir exists
- $path = BASE_SERVER_PATH.'application/cache/'.$one.'+'.$two.'+'.$three.'/';
- if(is_dir($path)) {
- //If request is live data, use shorter update
- if (in_array('live', array($one, $two, $three)) || in_array('index', array($one, $two, $three)))
- $valid = CACHE_VALID_LIVE;
- //Check cache, invalidate after set time
- $cache_mod = filemtime($path.'.');
- $time = (int) ((time() - $cache_mod) / 60);
- if ($time > $valid) {
- //Remove cache. First delete files then rm folder
- array_map('unlink', glob($path.'*'));
- rmdir($path.'/');
- }//end if cache still valid
- }//end if dir exists
- }//end invalidate_cache
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement