/** * Get multiple values from the cache. * * @param array $keys An array of keys to get * * @return array An array of JSON objects */ public function mget(array $keys = array()) { $values = $this->client->mget($keys); $rtn = []; // The Redis extension returns false not null for nonexistent // values. For consistency's sake, we spoof that here foreach ($keys as $index => $key) { $value = $values[$index]; $rtn[$this->instance->unkey($key)] = $value; } return $rtn; }
/** * Get multiple values from the cache. * * @param array $keys An array of keys to get * * @return array An array of JSON objects */ public function mget(array $keys = array()) { $values = $this->client->getMulti($keys); $rtn = []; // The Memcached extension returns false not null for nonexistent // values. For consistency's sake, we spoof that here foreach ($keys as $key) { if (!isset($values[$key]) || $values[$key] === false) { $values[$key] = null; } $rtn[$this->instance->unkey($key)] = $values[$key]; } return $rtn; }
/** * Tests that the instance key is removed from keys. * * @covers Molovo\Amnesia\Cache\Instance::unkey */ public function testUnkey() { $str = '0b4e02e6.a.test.key'; $key = static::$instance->unkey($str); $expected = 'a.test.key'; verify($key)->equals($expected); }
/** * Tests that the database can be flushed correctly. * * @depends testBootstrap * * @covers Molovo\Amnesia\Cache\Instance::flush * @covers Molovo\Amnesia\Driver\File::flush */ public function testFlush() { $keys = static::$instance->keys(); verify($keys)->notEquals([]); static::$instance->flush(); $keys = static::$instance->keys(); verify($keys)->equals([]); }
/** * Get multiple values from the cache. * * @param array $keys An array of keys to get * * @return array An array of JSON objects */ public function mget(array $keys = array()) { $values = []; foreach ($keys as $key) { $values[$this->instance->unkey($key)] = $this->get($key); } return $values; }
/** * Test that multiple values can be cleared correctly. * * @depends testBootstrap * * @covers Molovo\Amnesia\Cache\Instance::mclear * @covers Molovo\Amnesia\Driver\Memcached::mclear * * @uses Molovo\Amnesia\Cache\Instance::mset * @uses Molovo\Amnesia\Cache\Instance::mget * @uses Molovo\Amnesia\Cache\Instance::encode * @uses Molovo\Amnesia\Cache\Instance::decode * @uses Molovo\Amnesia\Driver\Memcached::mset * @uses Molovo\Amnesia\Driver\Memcached::mget */ public function testClearMultiple() { $set = ['first' => 'value', 'second' => 'value', 'third' => 'value']; static::$instance->mset($set); $value = static::$instance->mget(array_keys($set)); verify($value)->equals($set); static::$instance->mclear(array_keys($set)); $value = static::$instance->mget(array_keys($set)); verify($value)->equals(['first' => null, 'second' => null, 'third' => null]); }
/** * Clear the session data from the cache. * * @param string $id The ID of the current session * * @return bool */ public function destroy($id) { $this->checkId($id); $this->storage->clear('session.' . $id); return true; }