Memcached.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. if ( ! defined('BASE_PATH')) exit('No direct script access allowed');
  3. class StorageHandle{
  4. public $instance;
  5. public function __construct(){
  6. //判断环境
  7. @include('BaeMemcache.class.php');
  8. if(class_exists('BaeMemcache')){
  9. $this->instance = new BaeMemcache();
  10. }elseif(class_exists('Memcache')){
  11. $this->instance = new Memcache();
  12. if(method_exists('Memcache','init')){
  13. $this->instance->init();
  14. }else{
  15. $this->instance->connect(defined(CS_AK)?CS_AK:'127.0.0.1',defined(CS_SK)?CS_SK:'11211');
  16. }
  17. }else{
  18. die('No memcache.');
  19. }
  20. }
  21. public function exists($filename){
  22. return $this->instance->get($this->get_file($filename));
  23. }
  24. public function read($filename){
  25. return $this->instance->get($this->get_file($filename));
  26. }
  27. public function write($name,$content){
  28. return $this->instance->set($this->get_file($name),$content);
  29. }
  30. public function url($name){
  31. return false;
  32. }
  33. public function error(){
  34. return false;
  35. }
  36. public function delete($name){
  37. return $this->instance->delete($this->get_file($name));
  38. }
  39. private function get_file($name){
  40. return md5($name);
  41. }
  42. }