[ 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_MEMCACHE_PORT')) 17 { 18 define('PHPBB_ACM_MEMCACHE_PORT', 11211); 19 } 20 21 if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS')) 22 { 23 define('PHPBB_ACM_MEMCACHE_COMPRESS', false); 24 } 25 26 if (!defined('PHPBB_ACM_MEMCACHE_HOST')) 27 { 28 define('PHPBB_ACM_MEMCACHE_HOST', 'localhost'); 29 } 30 31 if (!defined('PHPBB_ACM_MEMCACHE')) 32 { 33 //can define multiple servers with host1/port1,host2/port2 format 34 define('PHPBB_ACM_MEMCACHE', PHPBB_ACM_MEMCACHE_HOST . '/' . PHPBB_ACM_MEMCACHE_PORT); 35 } 36 37 /** 38 * ACM for Memcached 39 */ 40 class memcache extends \phpbb\cache\driver\memory 41 { 42 var $extension = 'memcache'; 43 44 var $memcache; 45 var $flags = 0; 46 47 function __construct() 48 { 49 // Call the parent constructor 50 parent::__construct(); 51 52 $this->memcache = new \Memcache; 53 foreach (explode(',', PHPBB_ACM_MEMCACHE) as $u) 54 { 55 preg_match('#(.*)/(\d+)#', $u, $parts); 56 $this->memcache->addServer(trim($parts[1]), (int) trim($parts[2])); 57 } 58 $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0; 59 } 60 61 /** 62 * {@inheritDoc} 63 */ 64 function unload() 65 { 66 parent::unload(); 67 68 $this->memcache->close(); 69 } 70 71 /** 72 * {@inheritDoc} 73 */ 74 function purge() 75 { 76 $this->memcache->flush(); 77 78 parent::purge(); 79 } 80 81 /** 82 * Fetch an item from the cache 83 * 84 * @access protected 85 * @param string $var Cache key 86 * @return mixed Cached data 87 */ 88 function _read($var) 89 { 90 return $this->memcache->get($this->key_prefix . $var); 91 } 92 93 /** 94 * Store data in the cache 95 * 96 * @access protected 97 * @param string $var Cache key 98 * @param mixed $data Data to store 99 * @param int $ttl Time-to-live of cached data 100 * @return bool True if the operation succeeded 101 */ 102 function _write($var, $data, $ttl = 2592000) 103 { 104 if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl)) 105 { 106 return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl); 107 } 108 return true; 109 } 110 111 /** 112 * Remove an item from the cache 113 * 114 * @access protected 115 * @param string $var Cache key 116 * @return bool True if the operation succeeded 117 */ 118 function _delete($var) 119 { 120 return $this->memcache->delete($this->key_prefix . $var); 121 } 122 }
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 |