Example #1
0
 /**
  * Initialise data for configuration
  * @return void
  */
 protected function initData()
 {
     $data = $this->cache->load($this->cacheId);
     if (false === $data) {
         $data = $this->reader->read();
         $this->cache->save(serialize($data), $this->cacheId, $this->cacheTags);
     } else {
         $data = unserialize($data);
     }
     $this->merge($data);
 }
Example #2
0
 /**
  * First tries to find the class in the cache. If the class is not found in the cache, then it tries to find it
  * by using the registered maps.
  *
  * @param string $class Name of the class you are trying to find.
  *
  * @return bool True is retuned if the class if found and loaded into memory.
  */
 public function getClassFromCache($class)
 {
     // from cache
     if ($file = $this->cache->read($class)) {
         require $file;
     }
     // from disk
     if ($file = $this->findClass($class)) {
         $this->cache->save('wf.component.class_loader.' . $class, $file, 600, ['_wf', '_component', '_class_loader']);
         require $file;
     }
 }
Example #3
0
 /**
  * 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);
 }