cache.file.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * file 缓存
  4. */
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class CacheFile extends Cache{
  7. public function __construct($params = array()){
  8. $this->params['expire'] = C('cache.expire');
  9. $this->params['path'] = BASE_PATH.'/cache';
  10. $this->enable = true;
  11. }
  12. private function init(){
  13. return true;
  14. }
  15. private function isConnected(){
  16. return $this->enable;
  17. }
  18. public function get($key, $path=null){
  19. $filename = realpath($this->_path($key));
  20. if (is_file($filename)){
  21. return require($filename);
  22. }else{
  23. return false;
  24. }
  25. }
  26. public function set($key, $value, $path=null, $expire=null){
  27. $filename = $this->_path($key);
  28. if (false == write_file($filename,$value)){
  29. return false;
  30. }else{
  31. return true;
  32. }
  33. }
  34. public function rm($key, $path=null){
  35. $filename = realpath($this->_path($key));
  36. if (is_file($filename)) {
  37. @unlink($filename);
  38. }else{
  39. return false;
  40. }
  41. return true;
  42. }
  43. private function _path($key){
  44. switch (strtolower($key)) {
  45. // case '':
  46. // $path = BASE_DATA_PATH.'/cache';
  47. // break;
  48. default:
  49. $path = BASE_DATA_PATH.'/cache';
  50. break;
  51. }
  52. return $path.'/'.$key.'.php';
  53. }
  54. }
  55. ?>