fetch() public méthode

Fetches a previously stored value.
public fetch ( string $key ) : mixed
$key string Key associated with the value
Résultat mixed Stored value or FALSE if no value or an expired value is associated with the specified key
Exemple #1
0
 /**
  * Checks a given URL (+shortened) against the cache to verify if they were
  * previously posted on the channel.
  *
  * @param string $url          The URL to check against
  * @param string $shortenedUrl The shortened URL to check against
  *
  * @return bool
  */
 protected function checkUrlCache($url, $shortenedUrl)
 {
     $cache = array();
     $source = $this->getEvent()->getSource();
     /**
      * Transform URL (+shortened) into HEX CRC32 checksum to prevent
      * problems and minimize cache size for less bloat
      */
     $url = $this->getUrlChecksum($url);
     $shortenedUrl = $this->getUrlChecksum($shortenedUrl);
     $cache['url'] = $this->cache->fetch('urlCache');
     $cache['shortened'] = $this->cache->fetch('shortCache');
     $expire = $this->getConfig('url.expire', 1800);
     $this->debug("Cache expire: {$expire}");
     /**
      * If cache expiration is enabled, check if given URL has expired in
      * cache; if expire is disabled, check if the URL is listed
      */
     if ($expire > 0 && isset($cache['url'][$source], $cache['shortened'][$source])) {
         unset($cache, $url, $shortenedUrl, $expire);
         return true;
     }
     unset($cache, $url, $shortenedUrl, $expire);
     return false;
 }
Exemple #2
0
 /**
  * Updates the cache and adds the given URL (+shortened) to the cache. It
  * also handles cleaning the cache of old entries as well.
  *
  * @param string $url          The URL to add to the cache
  * @param string $shortenedUrl The shortened to add to the cache
  *
  * @return bool
  */
 protected function updateUrlCache($url, $shortenedUrl)
 {
     $cache = array();
     $source = $this->getEvent()->getSource();
     $cache['urlCache'] = $this->cache->fetch('urlCache');
     $cache['shortCache'] = $this->cache->fetch('shortCache');
     /**
      * Transform URL (+shortened) into HEX CRC32 checksum to prevent
      * problems and minimize cache size for less bloat
      */
     $url = $this->getUrlChecksum($url);
     $shortenedUrl = $this->getUrlChecksum($shortenedUrl);
     $time = time();
     /**
      * Handle URL cache and remove old entries that surpass the limit if
      * enabled
      */
     $cache['urlCache'][$source][$url] = $time;
     if ($this->limit > 0 && count($cache['urlCache'][$source]) > $this->limit) {
         asort($cache['urlCache'][$source], SORT_NUMERIC);
         array_shift($cache['urlCache'][$source]);
     }
     /**
      * Handle shortened cache and remove old entries that surpass the
      * limit if enabled
      */
     $cache['shortCache'][$source][$shortenedUrl] = $time;
     if ($this->limit > 0 && count($cache['shortCache'][$source]) > $this->limit) {
         asort($cache['shortCache'][$source], SORT_NUMERIC);
         array_shift($cache['shortCache'][$source]);
     }
     $this->cache->store('urlCache', $cache['urlCache'], $this->expire);
     $this->cache->store('shortCache', $cache['shortCache'], $this->expire);
     unset($url, $shortenedUrl, $time);
 }