*/ class common_persistence_InMemoryKvDriver implements common_persistence_KvDriver, common_persistence_Purgable { /** * @var array */ protected $persistence = []; /** * * @see common_persistence_Driver::connect() */ function connect($id, array $params) { return new common_persistence_KeyValuePersistence($params, $this); } public function set($id, $value, $ttl = null, $nx = false) { $this->persistence[$id] = $value; return true; } public function get($id) { return $this->exists($id) ? $this->persistence[$id] : false; } public function exists($id) { return array_key_exists($id, $this->persistence); } public function del($id) { unset($this->persistence[$id]); return true; } public function purge() { $this->persistence = []; return true; } public function incr($id) { if (!isset($this->persistence[$id])) { $this->persistence[$id] = 0; } if (!is_int($this->persistence[$id])) { throw new common_exception_InconsistentData('Cannot increment non intvalue for ' . $id); } return ++$this->persistence[$id]; } public function decr($id) { if (!isset($this->persistence[$id])) { $this->persistence[$id] = 0; } if (!is_int($this->persistence[$id])) { throw new common_exception_InconsistentData('Cannot decrement non intvalue for ' . $id); } return --$this->persistence[$id]; } }