コード例 #1
0
ファイル: Memory.php プロジェクト: comelyio/framework-kernel
 /**
  * @param string $key
  * @param string $instanceOf
  * @param callable|null $notFound
  * @return mixed|null
  */
 public function find(string $key, string $instanceOf, callable $notFound = null)
 {
     // Check in runtime memory
     if ($this->repo->has($key)) {
         $pull = $this->repo->pull($key);
         if (is_object($pull) && is_a($pull, $instanceOf)) {
             return $pull;
         }
     }
     // Check in cache
     if (isset($this->cache)) {
         $cached = $this->cache->get($key);
         if (is_object($cached) && is_a($cached, $instanceOf)) {
             return $cached;
         }
     }
     if (is_callable($notFound)) {
         $callBack = call_user_func($notFound);
         if (is_object($callBack)) {
             $this->set($key, clone $callBack);
             return $callBack;
         }
     }
     return null;
 }
コード例 #2
0
ファイル: Cache.php プロジェクト: comelyio/comely
 /**
  * @param string $id
  * @return string
  * @throws StorageException
  */
 public function read(string $id) : string
 {
     $read = $this->cache->get("sess_" . $id);
     if (empty($read)) {
         throw StorageException::readError(__METHOD__, 'Not found');
     }
     return $read;
 }