/** * Find a menu * * @param string $id menu identifier * @param array $with relation * @return Menu */ public function find($id, $with = []) { if (!isset($this->bag[$id])) { $this->bag[$id] = $this->repo->find($id, $with); } return $this->bag[$id]; }
/** * Find a menu * * @param string $id menu identifier * @param array $with relation * @return Menu */ public function find($id, $with = []) { $key = $this->getCacheKey($id); return $this->cache->has($key) ? $this->cache->get($key) : call_user_func(function () use($key, $id, $with) { if ($menu = $this->repo->find($id, $with)) { $this->cache->put($key, $menu); } return $menu; }); }
/** * Find a menu * * @param string $id menu identifier * @param array $with relation * @return Menu */ public function find($id, $with = []) { $key = $this->getCacheKey($id); $subKey = $this->getWithKey($with); $data = $this->cache->get($key); if (!$data || !isset($data[$subKey])) { if ($menu = $this->repo->find($id, $with)) { $data = $data ?: []; $data[$subKey] = $menu; $this->cache->put($key, $data); } } else { $menu = $data[$subKey]; } return $menu; }
/** * Get menu * * @param string $id menu identifier * @param array $with relation * @return Menu */ public function get($id, $with = []) { return $this->repo->find($id, $with); }