CacheXcacheService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class CacheXcacheService extends CacheService
  10. {
  11. private $dir;
  12. /**
  13. +----------------------------------------------------------
  14. * 架构函数
  15. +----------------------------------------------------------
  16. * @access public
  17. +----------------------------------------------------------
  18. */
  19. public function __construct()
  20. {
  21. if ( !function_exists('xcache_info') ) {
  22. return false;
  23. }
  24. $this->type = strtoupper(substr(__CLASS__,6));
  25. $this->expire = 36000;
  26. $this->dir = "";
  27. }
  28. /**
  29. +----------------------------------------------------------
  30. * 读取缓存
  31. +----------------------------------------------------------
  32. * @access public
  33. +----------------------------------------------------------
  34. * @param string $name 缓存变量名
  35. +----------------------------------------------------------
  36. * @return mixed
  37. +----------------------------------------------------------
  38. */
  39. public function get($name)
  40. {
  41. if(IS_DEBUG)return false;
  42. $var_name = md5($this->dir.$name);
  43. global $$var_name;
  44. if($$var_name)
  45. {
  46. return $$var_name;
  47. }
  48. if(function_exists("xcache_isset"))
  49. {
  50. if (xcache_isset($var_name)) {
  51. if(function_exists("xcache_get"))
  52. $data = xcache_get($var_name);
  53. $$var_name = $data;
  54. return $data;
  55. }
  56. }
  57. return false;
  58. }
  59. /**
  60. +----------------------------------------------------------
  61. * 写入缓存
  62. +----------------------------------------------------------
  63. * @access public
  64. +----------------------------------------------------------
  65. * @param string $name 缓存变量名
  66. * @param mixed $value 存储数据
  67. +----------------------------------------------------------
  68. * @return boolen
  69. +----------------------------------------------------------
  70. */
  71. public function set($name, $value,$expire ="-1")
  72. {
  73. if(IS_DEBUG)return false;
  74. if($expire=='-1') $expire = 3600*24;
  75. $key = md5($this->dir.$name);
  76. $this->log_names($key);
  77. if(function_exists("xcache_set"))
  78. return xcache_set($key, $value, $expire);
  79. else
  80. return false;
  81. }
  82. /**
  83. +----------------------------------------------------------
  84. * 删除缓存
  85. +----------------------------------------------------------
  86. * @access public
  87. +----------------------------------------------------------
  88. * @param string $name 缓存变量名
  89. +----------------------------------------------------------
  90. * @return boolen
  91. +----------------------------------------------------------
  92. */
  93. public function rm($name)
  94. {
  95. if(function_exists("xcache_unset"))
  96. {
  97. $key = md5($this->dir.$name);
  98. return xcache_unset($key);
  99. }
  100. }
  101. public function clear()
  102. {
  103. $names = $this->get_names();
  104. foreach($names as $name)
  105. {
  106. xcache_unset($name);
  107. }
  108. $this->del_name_logs();
  109. }
  110. public function set_dir($dir='')
  111. {
  112. if($dir!='')
  113. {
  114. $this->dir = md5($dir);
  115. }
  116. }
  117. }//类定义结束
  118. ?>