Cachearium\Backend\CacheRAM::get PHP Method

get() public method

public get ( CacheKey $k )
$k Cachearium\CacheKey
    public function get(CacheKey $k)
    {
        // @codeCoverageIgnoreStart
        if (!$this->enabled) {
            throw new NotCachedException();
        }
        // @codeCoverageIgnoreEnd
        if (!is_string($k->sub)) {
            $sub = md5(serialize($k->sub));
        } else {
            $sub = $k->sub;
        }
        $this->checkValidArgs($k);
        $idx = $this->namespace . $k->base . $k->id;
        if (isset($this->storage[$idx]) and array_key_exists($sub, $this->storage[$idx])) {
            $this->log(CacheLogEnum::ACCESSED, $k);
            return $this->storage[$idx][$sub];
        }
        $this->log(CacheLogEnum::MISSED, $k);
        throw new NotCachedException();
    }

Usage Example

 /**
  * (non-PHPdoc)
  * @see \Cachearium\Backend\CacheRAM::get()
  */
 public function get(CacheKey $k)
 {
     // @codeCoverageIgnoreStart
     if (!$this->enabled) {
         throw new NotCachedException();
     }
     // @codeCoverageIgnoreEnd
     // see if it is in RAM
     $should_log = $this->should_log;
     try {
         $this->should_log = false;
         $data = parent::get($k);
         $this->should_log = $should_log;
         $this->log(CacheLogEnum::PREFETCHED, $k);
         return $data;
     } catch (NotCachedException $e) {
         $this->should_log = $should_log;
     }
     $group = $this->hashKey($k);
     $this->fetches++;
     $retval = $this->memcached->get($group);
     $this->log($retval !== false ? CacheLogEnum::ACCESSED : CacheLogEnum::MISSED, $k);
     if ($retval == false) {
         throw new NotCachedException();
     }
     $x = unserialize($retval);
     if ($x === false) {
         throw new NotCachedException();
     }
     parent::store($x, $k);
     return $x;
 }