/** * Retrieve object from cache. * * Gets an object from cache based on $key and $group. In order to fully support the $cache_cb and $cas_token * parameters, the runtime cache is ignored by this function if either of those values are set. If either of * those values are set, the request is made directly to the memcached server for proper handling of the * callback and/or token. Note that the $cas_token variable cannot be directly passed to the function. The * variable need to be first defined with a non null value. * * If using the $cache_cb argument, the new value will always have an expiration of time of 0 (forever). This * is a limitation of the Memcached PECL extension. * * @link http://www.php.net/manual/en/memcached.get.php * * @param string $key The key under which to store the value. * @param string $group The group value appended to the $key. * @param bool $force Whether or not to force a cache invalidation. * @param null|bool $found Variable passed by reference to determine if the value was found or not. * @param string $server_key The key identifying the server to store the value on. * @param bool $byKey True to store in internal cache by key; false to not store by key * @param null|callable $cache_cb Read-through caching callback. * @param null|float $cas_token The variable to store the CAS token in. * @return bool|mixed Cached object value. */ public function get($key, $group = 'default', $force = false, &$found = null, $server_key = '', $byKey = false, $cache_cb = NULL, &$cas_token = NULL) { $derived_key = $this->buildKey($key, $group); // Assume object is not found $found = false; // If either $cache_db, or $cas_token is set, must hit Memcached and bypass runtime cache if (func_num_args() > 6 && !in_array($group, $this->no_mc_groups)) { if (false !== $byKey) { $value = $this->mc->getByKey($server_key, $derived_key, $cache_cb, $cas_token); } else { $value = $this->mc->get($derived_key, $cache_cb, $cas_token); } } else { if (isset($this->cache[$derived_key])) { $found = true; return is_object($this->cache[$derived_key]) ? clone $this->cache[$derived_key] : $this->cache[$derived_key]; } elseif (in_array($group, $this->no_mc_groups)) { return false; } else { if (false !== $byKey) { $value = $this->mc->getByKey($server_key, $derived_key); } else { $value = $this->mc->get($derived_key); } } } if (Memcached::RES_SUCCESS === $this->getResultCode()) { $this->add_to_internal_cache($derived_key, $value); $found = true; } return is_object($value) ? clone $value : $value; }
public function getValueByKey($key) { return parent::getByKey($this->server, $key); }