| | |
| | | private $index; |
| | | private $table; |
| | | private $debug; |
| | | private $index_changed = false; |
| | | private $cache = array(); |
| | | private $cache_changes = array(); |
| | | private $cache_sums = array(); |
| | | private $max_packet = -1; |
| | | |
| | | const DEBUG_LINE_LENGTH = 4096; |
| | | |
| | | |
| | | /** |
| | |
| | | function set($key, $data) |
| | | { |
| | | $this->cache[$key] = $data; |
| | | $this->cache_changed = true; |
| | | $this->cache_changes[$key] = true; |
| | | } |
| | | |
| | |
| | | // Remove all keys |
| | | if ($key === null) { |
| | | $this->cache = array(); |
| | | $this->cache_changed = false; |
| | | $this->cache_changes = array(); |
| | | $this->cache_sums = array(); |
| | | } |
| | |
| | | */ |
| | | function close() |
| | | { |
| | | if (!$this->cache_changed) { |
| | | return; |
| | | } |
| | | |
| | | foreach ($this->cache as $key => $data) { |
| | | // The key has been used |
| | | if ($this->cache_changes[$key]) { |
| | |
| | | } |
| | | } |
| | | |
| | | $this->write_index(); |
| | | if ($this->index_changed) { |
| | | $this->write_index(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | if ($this->type == 'memcache' || $this->type == 'apc') { |
| | | return $this->add_record($this->ckey($key), $data); |
| | | $result = $this->add_record($this->ckey($key), $data); |
| | | |
| | | // make sure index will be updated |
| | | if ($result && !array_key_exists($key, $this->cache_sums)) { |
| | | $this->cache_sums[$key] = true; |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | $key_exists = array_key_exists($key, $this->cache_sums); |
| | |
| | | } |
| | | } |
| | | |
| | | if ($result) { |
| | | $this->index_changed = true; |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if ($result) { |
| | | $this->index_changed = true; |
| | | } |
| | | |
| | | if ($index) { |
| | | if (($idx = array_search($key, $this->index)) !== false) { |
| | | unset($this->index[$idx]); |
| | |
| | | |
| | | // Make sure index contains new keys |
| | | foreach ($this->cache as $key => $value) { |
| | | if ($value !== null) { |
| | | if (array_search($key, $this->index) === false) { |
| | | $this->index[] = $key; |
| | | } |
| | | if ($value !== null && !in_array($key, $this->index)) { |
| | | $this->index[] = $key; |
| | | } |
| | | } |
| | | |
| | | // new keys added using self::write() |
| | | foreach ($this->cache_sums as $key => $value) { |
| | | if ($value === true && !in_array($key, $this->index)) { |
| | | $this->index[] = $key; |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private function debug($type, $key, $data = null, $result = null) |
| | | { |
| | | $line = '[' . (++$this->debug_count) . '] ' . strtoupper($type) . ' ' . $key; |
| | | $line = strtoupper($type) . ' ' . $key; |
| | | |
| | | if ($data !== null) { |
| | | $line .= ' ' . ($this->packed ? $data : serialize($data)); |
| | | |
| | | if (($len = strlen($line)) > self::DEBUG_LINE_LENGTH) { |
| | | $diff = $len - self::DEBUG_LINE_LENGTH; |
| | | $line = substr($line, 0, self::DEBUG_LINE_LENGTH) . "... [truncated $diff bytes]"; |
| | | } |
| | | } |
| | | |
| | | if ($result !== null) { |
| | | $line .= ' [' . ($result ? 'TRUE' : 'FALSE') . ']'; |
| | | } |
| | | |
| | | rcube::write_log($this->type, $line); |
| | | rcube::debug($this->type, $line, $result); |
| | | } |
| | | } |