6 * @copyright (c) 2005, 2009 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
19 // Include the abstract base
20 if (!class_exists('acm_memory'))
22 require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
25 if (!defined('PHPBB_ACM_MEMCACHE_PORT'))
27 define('PHPBB_ACM_MEMCACHE_PORT', 11211);
30 if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
32 define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
35 if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
37 define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
40 if (!defined('PHPBB_ACM_MEMCACHE'))
42 //can define multiple servers with host1/port1,host2/port2 format
43 define('PHPBB_ACM_MEMCACHE', PHPBB_ACM_MEMCACHE_HOST . '/' . PHPBB_ACM_MEMCACHE_PORT);
50 class acm extends acm_memory
52 var $extension = 'memcache';
59 // Call the parent constructor
62 $this->memcache = new Memcache;
63 foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u)
65 $parts = explode('/', $u);
66 $this->memcache->addServer(trim($parts[0]), trim($parts[1]));
68 $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;
72 * Unload the cache resources
80 $this->memcache->close();
90 $this->memcache->flush();
96 * Fetch an item from the cache
99 * @param string $var Cache key
100 * @return mixed Cached data
104 return $this->memcache->get($this->key_prefix . $var);
108 * Store data in the cache
111 * @param string $var Cache key
112 * @param mixed $data Data to store
113 * @param int $ttl Time-to-live of cached data
114 * @return bool True if the operation succeeded
116 function _write($var, $data, $ttl = 2592000)
118 if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl))
120 return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl);
126 * Remove an item from the cache
129 * @param string $var Cache key
130 * @return bool True if the operation succeeded
132 function _delete($var)
134 return $this->memcache->delete($this->key_prefix . $var);