/** * Retrieve response from cache if it exists otherwise make a GET request. * * @param string $endpoint Request endpoint. * @param string $root_property The theme/plugin slug or WordPress version. * * @return SSNepenthe\Soter\WPVulnDB\Response * * @throws \InvalidArgumentException When endpoint is not a string. * @throws \InvalidArgumentException When root_property is not a string. */ protected function get_and_cache($endpoint, $root_property) { if (!is_string($endpoint)) { throw new \InvalidArgumentException(sprintf('The endpoint parameter is required to be string, was: %s', gettype($endpoint))); } if (!is_string($root_property)) { throw new \InvalidArgumentException(sprintf('The root_property parameter is required to be string, was: %s', gettype($root_property))); } if ($this->cache->contains($endpoint)) { return new Response($this->cache->fetch($endpoint), $root_property); } $response = $this->http->get($endpoint); // @todo Filterable cache lifetime? $this->cache->save($endpoint, $response, 60 * 60 * 12); return new Response($response, $root_property); }