memory_driver_memcache.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: memory_driver_memcache.php 27449 2012-02-01 05:32:35Z zhangguosheng $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class memory_driver_memcache {
  12. public $cacheName = 'MemCache';
  13. public $enable;
  14. public $obj;
  15. public function env() {
  16. return extension_loaded('memcache');
  17. }
  18. public function init($config) {
  19. if (!$this->env()) {
  20. $this->enable = false;
  21. return;
  22. }
  23. if (!empty($config['server'])) {
  24. $this->obj = new Memcache;
  25. if ($config['pconnect']) {
  26. $connect = @$this->obj->pconnect($config['server'], $config['port']);
  27. } else {
  28. $connect = @$this->obj->connect($config['server'], $config['port']);
  29. }
  30. $this->enable = $connect ? true : false;
  31. }
  32. }
  33. public function get($key) {
  34. return $this->obj->get($key);
  35. }
  36. public function getMulti($keys) {
  37. return $this->obj->get($keys);
  38. }
  39. public function set($key, $value, $ttl = 0) {
  40. return $this->obj->set($key, $value, MEMCACHE_COMPRESSED, $ttl);
  41. }
  42. public function rm($key) {
  43. return $this->obj->delete($key);
  44. }
  45. public function clear() {
  46. return $this->obj->flush();
  47. }
  48. public function inc($key, $step = 1) {
  49. return $this->obj->increment($key, $step);
  50. }
  51. public function dec($key, $step = 1) {
  52. return $this->obj->decrement($key, $step);
  53. }
  54. }
  55. ?>