public function get($key) { $this->validateKey($key); // Fetch the key from cache if ($cache = $this->getConfig()->getCache()) { if ($cache->contains($key)) { return $cache->get($key); } } // Fetch the key from database $filePointer = $this->getDatabase()->openFile(Database::FILE_READ); $data = false; foreach ($filePointer as $line) { $data = $this->getDataFromLine($line, $key); if ($data !== false) { $data = $this->decodeData($data); break; } } $this->getDatabase()->closeFile($filePointer); // Save the data to cache if ($cache && $data !== false) { $cache->set($key, $data); } return $data; }
public function get($key, callable $callback = null, $default = null) { $value = $this->cache->get($key); if (!isset($value)) { $value = $default; } if (is_callable($callback)) { return call_user_func($callback, $value); } return $value; }