root / trunk / phpBB / includes / acm / acm_memcache.php
History | View | Annotate | Download (2.2 KB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package acm |
| 5 | * @version $Id: acm_memcache.php 10342 2009-12-16 15:48:23Z acydburn $ |
| 6 | * @copyright (c) 2005, 2009 phpBB Group |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /**
|
| 12 | * @ignore |
| 13 | */ |
| 14 | if (!defined('IN_PHPBB')) |
| 15 | {
|
| 16 | exit;
|
| 17 | } |
| 18 | |
| 19 | // Include the abstract base
|
| 20 | if (!class_exists('acm_memory')) |
| 21 | {
|
| 22 | require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx"); |
| 23 | } |
| 24 | |
| 25 | if (!defined('PHPBB_ACM_MEMCACHE_PORT')) |
| 26 | {
|
| 27 | define('PHPBB_ACM_MEMCACHE_PORT', 11211); |
| 28 | } |
| 29 | |
| 30 | if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS')) |
| 31 | {
|
| 32 | define('PHPBB_ACM_MEMCACHE_COMPRESS', false); |
| 33 | } |
| 34 | |
| 35 | if (!defined('PHPBB_ACM_MEMCACHE_HOST')) |
| 36 | {
|
| 37 | define('PHPBB_ACM_MEMCACHE_HOST', 'localhost'); |
| 38 | } |
| 39 | |
| 40 | /**
|
| 41 | * ACM for Memcached |
| 42 | * @package acm |
| 43 | */ |
| 44 | class acm extends acm_memory |
| 45 | {
|
| 46 | var $extension = 'memcache'; |
| 47 | |
| 48 | var $memcache;
|
| 49 | var $flags = 0; |
| 50 | |
| 51 | function acm()
|
| 52 | {
|
| 53 | // Call the parent constructor
|
| 54 | parent::acm_memory(); |
| 55 | |
| 56 | $this->memcache = new Memcache; |
| 57 | $this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT);
|
| 58 | $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0; |
| 59 | } |
| 60 | |
| 61 | /**
|
| 62 | * Unload the cache resources |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | function unload()
|
| 67 | {
|
| 68 | parent::unload(); |
| 69 | |
| 70 | $this->memcache->close();
|
| 71 | } |
| 72 | |
| 73 | /**
|
| 74 | * Purge cache data |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | function purge()
|
| 79 | {
|
| 80 | $this->memcache->flush();
|
| 81 | |
| 82 | parent::purge(); |
| 83 | } |
| 84 | |
| 85 | /**
|
| 86 | * Fetch an item from the cache |
| 87 | * |
| 88 | * @access protected |
| 89 | * @param string $var Cache key |
| 90 | * @return mixed Cached data |
| 91 | */ |
| 92 | function _read($var)
|
| 93 | {
|
| 94 | return $this->memcache->get($this->key_prefix . $var); |
| 95 | } |
| 96 | |
| 97 | /**
|
| 98 | * Store data in the cache |
| 99 | * |
| 100 | * @access protected |
| 101 | * @param string $var Cache key |
| 102 | * @param mixed $data Data to store |
| 103 | * @param int $ttl Time-to-live of cached data |
| 104 | * @return bool True if the operation succeeded |
| 105 | */ |
| 106 | function _write($var, $data, $ttl = 2592000) |
| 107 | {
|
| 108 | if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl)) |
| 109 | {
|
| 110 | return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl); |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | /**
|
| 116 | * Remove an item from the cache |
| 117 | * |
| 118 | * @access protected |
| 119 | * @param string $var Cache key |
| 120 | * @return bool True if the operation succeeded |
| 121 | */ |
| 122 | function _delete($var)
|
| 123 | {
|
| 124 | return $this->memcache->delete($this->key_prefix . $var); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | ?> |