public function get(string $key)
    {
        Validation::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
        $file = $this->getDatabase()->readFromFile();
        $data = false;

        foreach ($file as $line) {
            /** @var Line $line */
            if ($line->getKey() == $key) {
                $data = $this->decodeData($line->getData());
                break;
            }
        }

        // Save the data to cache
        if ($cache && $data !== false) {
            $cache->set($key, $data);
        }

        return $data;
    }