| | |
| | | public $db; |
| | | |
| | | /** |
| | | * Instace of Memcache class. |
| | | * |
| | | * @var rcube_mdb2 |
| | | */ |
| | | public $memcache; |
| | | |
| | | /** |
| | | * Instace of rcube_session class. |
| | | * |
| | | * @var rcube_session |
| | |
| | | |
| | | private $texts; |
| | | private $address_books = array(); |
| | | private $caches = array(); |
| | | private $action_map = array(); |
| | | |
| | | |
| | |
| | | |
| | | return $this->db; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get global handle for memcache access |
| | | * |
| | | * @return object Memcache |
| | | */ |
| | | public function get_memcache() |
| | | { |
| | | if (!isset($this->memcache)) { |
| | | // no memcache support in PHP |
| | | if (!class_exists('Memcache')) { |
| | | $this->memcache = false; |
| | | return false; |
| | | } |
| | | |
| | | $this->memcache = new Memcache; |
| | | $mc_available = 0; |
| | | foreach ($this->config->get('memcache_hosts', array()) as $host) { |
| | | list($host, $port) = explode(':', $host); |
| | | if (!$port) $port = 11211; |
| | | // add server and attempt to connect if not already done yet |
| | | if ($this->memcache->addServer($host, $port) && !$mc_available) |
| | | $mc_available += intval($this->memcache->connect($host, $port)); |
| | | } |
| | | |
| | | if (!$mc_available) |
| | | $this->memcache = false; |
| | | } |
| | | |
| | | return $this->memcache; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Initialize and get cache object |
| | | * |
| | | * @param string $name Cache identifier |
| | | * @param string $type Cache type ('db', 'apc' or 'memcache') |
| | | * |
| | | * @return rcube_cache Cache object |
| | | */ |
| | | public function get_cache($name, $type) |
| | | { |
| | | if (!isset($this->caches[$name])) { |
| | | $this->caches[$name] = new rcube_cache($type, $_SESSION['user_id'], $name.'.'); |
| | | } |
| | | |
| | | return $this->caches[$name]; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | if (is_object($this->imap)) |
| | | return; |
| | | |
| | | $this->imap = new rcube_imap($this->db); |
| | | $this->imap = new rcube_imap(); |
| | | $this->imap->debug_level = $this->config->get('debug_level'); |
| | | $this->imap->skip_deleted = $this->config->get('skip_deleted'); |
| | | |
| | | // enable caching of imap data |
| | | if ($this->config->get('enable_caching')) { |
| | | $this->imap->set_caching(true); |
| | | $imap_cache = $this->config->get('imap_cache'); |
| | | $messages_cache = $this->config->get('messages_cache'); |
| | | // for backward compatybility |
| | | if ($imap_cache === null && $messages_cache === null && $this->config->get('enable_caching')) { |
| | | $imap_cache = 'db'; |
| | | $messages_cache = true; |
| | | } |
| | | if ($imap_cache) |
| | | $this->imap->set_caching($imap_cache); |
| | | if ($messages_cache) |
| | | $this->imap->set_messages_caching(true); |
| | | |
| | | // set pagesize from config |
| | | $this->imap->set_pagesize($this->config->get('pagesize', 50)); |
| | |
| | | $book->close(); |
| | | } |
| | | |
| | | foreach ($this->caches as $cache) { |
| | | if (is_object($cache)) |
| | | $cache->close(); |
| | | } |
| | | |
| | | if (is_object($this->imap)) |
| | | $this->imap->close(); |
| | | |