Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /*
  2. * Used to invalidate cache by three URIs and a timestamp
  3. *
  4. * Cache invalidation only happens after a certain predefined time has passed
  5. * Two times are set, one for normal slow data, another for faster data (live)
  6. * These are defined as constants CACHE_VALID and CACHE_VALID_LIVE
  7. * The timestamp of the files on disk is used to check when last the files were written
  8. * and then invalidated if that time is longer than set time
  9. *
  10. * @one (string) first URI, default "default"
  11. * @two (string) second URI, default "index"
  12. * @three (string) third URI, default "index"
  13. * @valid (int) valid time in minutes
  14. * @return (null)
  15. */
  16.  
  17.  
  18. function invalidate_cache($one = 'default', $two = 'index', $three = 'index', $valid = CACHE_VALID) {
  19. //Check if dir exists
  20. $path = BASE_SERVER_PATH.'application/cache/'.$one.'+'.$two.'+'.$three.'/';
  21. if(is_dir($path)) {
  22. //If request is live data, use shorter update
  23. if (in_array('live', array($one, $two, $three)) || in_array('index', array($one, $two, $three)))
  24. $valid = CACHE_VALID_LIVE;
  25. //Check cache, invalidate after set time
  26. $cache_mod = filemtime($path.'.');
  27. $time = (int) ((time() - $cache_mod) / 60);
  28. if ($time > $valid) {
  29. //Remove cache. First delete files then rm folder
  30. array_map('unlink', glob($path.'*'));
  31. rmdir($path.'/');
  32. }//end if cache still valid
  33. }//end if dir exists
  34. }//end invalidate_cache
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement