This can be faster than getting the value from the cache if the data is big.
In case a cache does not support this feature natively, this method will try to simulate it
but has no performance improvement over getting it.
Note that this method does not check whether the dependency associated
with the cached data, if there is any, has changed. So a call to [[get]]
may return false while exists returns true.
/** * @param callable $callback */ protected function cacheIterator($callback) { $i = 0; while (true) { $key = sprintf('assignments-%d', $i); if ($this->cache->exists($key)) { call_user_func($callback, $key); } else { break; } $i++; } }
/** * @param mixed $key * * @return boolean * * @see yii\caching\Cache::exist() */ public function exists($key) { return $this->cache->exists($key); }
/** * Check exist name * @param $name * @return mixed */ public function exists($name) { return $this->_cache->exists($this->prefix . $name); }