PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/cache/file.class.php

http://freewms.googlecode.com/
PHP | 82 lines | 50 code | 5 blank | 27 comment | 8 complexity | 13d612527670cb904c53ca49efaa06af MD5 | raw file
  1. <?php if(!defined('BASEPATH')) die('Access Denied');
  2. /*-------------------------------------------------
  3. * FreeWMS - A Free Website Management System
  4. * Ver:0.1.0 Update: 2010-05-16
  5. * Home: http://code.google.com/p/freewms
  6. * Copyright 2010, FreeWMS Team, SOVO, Neusoft
  7. * Released under the New BSD Licenses
  8. *-------------------------------------------------*/
  9. class Cache_Adapter {
  10. /**
  11. * ????
  12. * @param string $key ???
  13. * @param unknown $value ????
  14. */
  15. public static function set($key, $value) {
  16. $key = md5(SAFETY_STRING.$key);
  17. $path = BASEPATH.CACHE_PATH.'data/'.substr($key,0,2)."/".substr($key,2,2).'/';
  18. if(!is_dir($path)) {
  19. create_dir($path);
  20. }
  21. $cache_file = $path.$key.'.cache';
  22. $value = serialize($value);
  23. file_put_contents($cache_file, $value);
  24. clearstatcache();
  25. return TRUE;
  26. }
  27. /**
  28. * ????
  29. * @param string $key ???
  30. * @return unknown
  31. */
  32. public static function get($key, $expires = NULL) {
  33. $key = md5(SAFETY_STRING.$key);
  34. $path = BASEPATH.CACHE_PATH.'data/'.substr($key,0,2)."/".substr($key,2,2).'/';
  35. $cache_file = $path.$key.'.cache';
  36. if(!is_file($cache_file)) {
  37. return FALSE;
  38. }else{
  39. if($expires == NULL) {
  40. $expires = CACHE_EXPIRES;
  41. }
  42. $file_create_time = filemtime($cache_file);
  43. if($expires > 0 && gmmktime() - $file_create_time > $expires) {
  44. return FALSE;
  45. }else{
  46. return unserialize(file_get_contents($cache_file));
  47. }
  48. }
  49. }
  50. /**
  51. * ??????
  52. * @param string $key ???
  53. * @return bool
  54. */
  55. public static function delete($key) {
  56. $key = md5(SAFETY_STRING.$key);
  57. $path = BASEPATH.CACHE_PATH.'data/'.substr($key,0,2)."/".substr($key,2,2).'/';
  58. $cache_file = $path.$key.'.cache';
  59. @unlink($cache_file);
  60. clearstatcache();
  61. return TRUE;
  62. }
  63. /**
  64. * ????????
  65. * @return bool
  66. */
  67. public static function clear() {
  68. $path = BASEPATH.CACHE_PATH.'data';
  69. rm_file($path);
  70. if(!is_dir($path)) {
  71. create_dir($path);
  72. }
  73. clearstatcache();
  74. return TRUE;
  75. }
  76. }
  77. /* End of this file */