[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache\driver; 15 16 if (!defined('PHPBB_ACM_MEMCACHED_PORT')) 17 { 18 define('PHPBB_ACM_MEMCACHED_PORT', 11211); 19 } 20 21 if (!defined('PHPBB_ACM_MEMCACHED_COMPRESS')) 22 { 23 define('PHPBB_ACM_MEMCACHED_COMPRESS', true); 24 } 25 26 if (!defined('PHPBB_ACM_MEMCACHED_HOST')) 27 { 28 define('PHPBB_ACM_MEMCACHED_HOST', 'localhost'); 29 } 30 31 if (!defined('PHPBB_ACM_MEMCACHED')) 32 { 33 //can define multiple servers with host1/port1,host2/port2 format 34 define('PHPBB_ACM_MEMCACHED', PHPBB_ACM_MEMCACHED_HOST . '/' . PHPBB_ACM_MEMCACHED_PORT); 35 } 36 37 /** 38 * ACM for Memcached 39 */ 40 class memcached extends \phpbb\cache\driver\memory 41 { 42 /** @var string Extension to use */ 43 protected $extension = 'memcached'; 44 45 /** @var \Memcached Memcached class */ 46 protected $memcached; 47 48 /** @var int Flags */ 49 protected $flags = 0; 50 51 /** 52 * Memcached constructor 53 */ 54 public function __construct() 55 { 56 // Call the parent constructor 57 parent::__construct(); 58 59 $this->memcached = new \Memcached(); 60 $this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); 61 // Memcached defaults to using compression, disable if we don't want 62 // to use it 63 if (!PHPBB_ACM_MEMCACHED_COMPRESS) 64 { 65 $this->memcached->setOption(\Memcached::OPT_COMPRESSION, false); 66 } 67 68 foreach (explode(',', PHPBB_ACM_MEMCACHED) as $u) 69 { 70 preg_match('#(.*)/(\d+)#', $u, $parts); 71 $this->memcached->addServer(trim($parts[1]), (int) trim($parts[2])); 72 } 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 public function unload() 79 { 80 parent::unload(); 81 82 unset($this->memcached); 83 } 84 85 /** 86 * {@inheritDoc} 87 */ 88 public function purge() 89 { 90 $this->memcached->flush(); 91 92 parent::purge(); 93 } 94 95 /** 96 * Fetch an item from the cache 97 * 98 * @param string $var Cache key 99 * 100 * @return mixed Cached data 101 */ 102 protected function _read($var) 103 { 104 return $this->memcached->get($this->key_prefix . $var); 105 } 106 107 /** 108 * Store data in the cache 109 * 110 * @param string $var Cache key 111 * @param mixed $data Data to store 112 * @param int $ttl Time-to-live of cached data 113 * @return bool True if the operation succeeded 114 */ 115 protected function _write($var, $data, $ttl = 2592000) 116 { 117 if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl)) 118 { 119 return $this->memcached->set($this->key_prefix . $var, $data, $ttl); 120 } 121 return true; 122 } 123 124 /** 125 * Remove an item from the cache 126 * 127 * @param string $var Cache key 128 * @return bool True if the operation succeeded 129 */ 130 protected function _delete($var) 131 { 132 return $this->memcached->delete($this->key_prefix . $var); 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |