Find an existing cache by ID

@param int $id
@param int|null $siteId
@return BaseElement|ElementInterface|null
338756
public function findCacheById(int $id, int $siteId = null)
    {

        // Resolve siteId
        $siteId = SiteHelper::resolveSiteId($siteId);

        // Check if already in addToCache
        if ($this->isCachedById($id, $siteId)) {
            return $this->cacheById[$siteId][$id];
        }

        return null;
    }
1230249
public static function findPostsCount($id)
    {
        $cache = Podium::getInstance()->podiumCache->getElement('user.postscount', $id);
        if ($cache === false) {
            $cache = (new Query)->from(Post::tableName())->where(['author_id' => $id])->count();
            Podium::getInstance()->podiumCache->setElement('user.postscount', $id, $cache);
        }
        return $cache;
    }
357266
public static function getFromCache($id)
    {
        $arrayCache = Configuration::getArrayCache();
        if ($arrayCache->contains($id)) {
            return $arrayCache->fetch($id);
        }

        $cacheDriver = Configuration::getCacheDriver();
        if ($cacheDriver !== null) {
            $cacheResult = $cacheDriver->fetch($id);
            if ($cacheResult !== false) {
                $arrayCache->save($id, $cacheResult);
                return $cacheResult;
            }
        }

        return null;
    }
1059425
public function findOrFail($id)
    {
        if ($this->refresh) {
            $this->forget($id);
        }
        return $this->cache->remember($this->keyPrefix . $id, $this->minutesToCache, function () use ($id) {
            return $this->decorated->findOrFail($id);
        });
    }
1133746
public function getLanguageBySite($siteId)
    {
        if ($this->hasLanguageBySite($siteId)) {
            return $this->languageBySites[self::SITE_ID_PREFIX.$siteId];
        }

        return null;
    }
163666
public function getCacheId($id)
    {
        if(is_array($id))
        {
            $tmp = "";
            foreach ($id as $key => $value)
            {
                $tmp .= $key . "_" . $value;
            }
            $id = $tmp;
        }
        return $this->addCacheIndex($this->table_name . '_' . $id);
    }
726386
public function get($id, $default = null)
    {

        $cacheId = $this->cache->key([$this->prototype(), $id]);

        if ($this->cache->has($cacheId)) {
            return $this->cache->get($cacheId);
        }

        if ($model = $this->parent->get($id)) {
            $this->cache->put($cacheId, $model);
        }

        return $model ? $model : $default;
    }
731053
protected function getFromFirstLevelCache($cacheId)
    {
        if (!empty(self::$firstLevelCache[$this->cacheName][$cacheId])) {
            return self::$firstLevelCache[$this->cacheName][$cacheId];
        }

        return null;
    }
1289660
public function findByIdentificationNumber($id)
    {
        $id = Lib::toInteger($id);
        $this->ensureIdIsInteger($id);

        if (empty($id)) {
            throw new AresException('IČ firmy musí být zadáno.');
        }

        $cachedFileName = $id.'_'.date($this->cacheStrategy).'.php';
        $cachedFile = $this->cacheDir.'/bas_'.$cachedFileName;
        $cachedRawFile = $this->cacheDir.'/bas_raw_'.$cachedFileName;

        if (is_file($cachedFile)) {
            return unserialize(file_get_contents($cachedFile));
        }

        // Sestaveni URL
        $url = $this->wrapUrl(sprintf(self::URL_BAS, $id));

        try {
            $aresRequest = file_get_contents($url, null, stream_context_create($this->contextOptions));
            if ($this->debug) {
                file_put_contents($cachedRawFile, $aresRequest);
            }
            $aresResponse = simplexml_load_string($aresRequest);

            if ($aresResponse) {
                $ns = $aresResponse->getDocNamespaces();
                $data = $aresResponse->children($ns['are']);
                $elements = $data->children($ns['D'])->VBAS;

                $ico = (int) $elements->ICO;
                if ($ico !== $id) {
                    throw new AresException('IČ firmy nebylo nalezeno.');
                }

                $record = new AresRecord();

                $record->setCompanyId(strval($elements->ICO));
                $record->setTaxId(strval($elements->DIC));
                $record->setCompanyName(strval($elements->OF));
                $record->setStreet(strval($elements->AA->NU));

                if (strval($elements->AA->CO)) {
                    $record->setStreetHouseNumber(strval($elements->AA->CD));
                    $record->setStreetOrientationNumber(strval($elements->AA->CO));
                } else {
                    $record->setStreetHouseNumber(strval($elements->AA->CD));
                }

                if (strval($elements->AA->N) === 'Praha') { //Praha
                    $record->setTown(strval($elements->AA->NMC).' - '.strval($elements->AA->NCO));
                } elseif (strval($elements->AA->NCO) !== strval($elements->AA->N)) { //Ostrava
                    $record->setTown(strval($elements->AA->N).' - '.strval($elements->AA->NCO));
                } else {
                    $record->setTown(strval($elements->AA->N));
                }

                $record->setZip(strval($elements->AA->PSC));
            } else {
                throw new AresException('Databáze ARES není dostupná.');
            }
        } catch (\Exception $e) {
            throw new AresException($e->getMessage());
        }

        file_put_contents($cachedFile, serialize($record));

        return $record;
    }
1207821
public function findInResById($id)
    {
        $id = Lib::toInteger($id);
        $this->ensureIdIsInteger($id);

        // Sestaveni URL
        $url = $this->wrapUrl(sprintf(self::URL_RES, $id));

        $cachedFileName = $id.'_'.date($this->cacheStrategy).'.php';
        $cachedFile = $this->cacheDir.'/res_'.$cachedFileName;
        $cachedRawFile = $this->cacheDir.'/res_raw_'.$cachedFileName;

        if (is_file($cachedFile)) {
            return unserialize(file_get_contents($cachedFile));
        }

        try {
            $aresRequest = file_get_contents($url, null, stream_context_create($this->contextOptions));
            if ($this->debug) {
                file_put_contents($cachedRawFile, $aresRequest);
            }
            $aresResponse = simplexml_load_string($aresRequest);

            if ($aresResponse) {
                $ns = $aresResponse->getDocNamespaces();
                $data = $aresResponse->children($ns['are']);
                $elements = $data->children($ns['D'])->Vypis_RES;

                if (strval($elements->ZAU->ICO) === $id) {
                    $record = new AresRecord();
                    $record->setCompanyId(strval($id));
                    $record->setTaxId($this->findVatById($id));
                    $record->setCompanyName(strval($elements->ZAU->OF));
                    $record->setStreet(strval($elements->SI->NU));
                    $record->setStreetHouseNumber(strval($elements->SI->CD));
                    $record->setStreetOrientationNumber(strval($elements->SI->CO));
                    $record->setTown(strval($elements->SI->N));
                    $record->setZip(strval($elements->SI->PSC));
                } else {
                    throw new AresException('IČ firmy nebylo nalezeno.');
                }
            } else {
                throw new AresException('Databáze ARES není dostupná.');
            }
        } catch (\Exception $e) {
            throw new AresException($e->getMessage());
        }
        file_put_contents($cachedFile, serialize($record));

        return $record;
    }
1206187
public function getById($id, $srid = null)
    {
        $rows = $this->getSelectQueryBuilder($srid)
            ->where($this->getUniqueId() . " = :id")
            ->setParameter('id', $id)
            ->execute()
            ->fetchAll();
        $this->prepareResults($rows, $srid);
        return reset($rows);
    }
481641
public function getBlockById(int $blockId, int $siteId = null)
    {
        /** @var SuperTableBlock|null $block */
        $block = Craft::$app->getElements()->getElementById($blockId, SuperTableBlockElement::class, $siteId);

        return $block;
    }
55213
public function buildPagesResourceId(
        $siteId
    ) {
        return $this->resourceName->get(
            ResourceName::RESOURCE_SITES,
            $siteId,
            ResourceName::RESOURCE_PAGES
        );
    }
402633
public function getSiteInfo($siteId)
    {
        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->_em->createQueryBuilder();
        $queryBuilder->select(
            'partial site.{
                owner,
                theme,
                status,
                favIcon,
                loginPage,
                notAuthorizedPage,
                siteLayout,
                siteTitle,
                siteId
            },
            language,
            country'
        )->from(\Rcm\Entity\Site::class, 'site')
            ->join('site.country', 'country')
            ->join('site.language', 'language')
            ->where('site.siteId = :siteId')
            ->setParameter('siteId', $siteId);

        try {
            return $queryBuilder->getQuery()->getSingleResult(
                Query::HYDRATE_ARRAY
            );
        } catch (NoResultException $e) {
            return null;
        }
    }
164946
public function findUsageReferenceInOtherSite($siteId, $entities)
    {
        $usedOtherSite = array();
        $supportedEntities = array(BlockInterface::ENTITY_TYPE, ContentInterface::ENTITY_TYPE);
        /** @var UseTrackableInterface $entity */
        foreach ($entities as $entity) {
            $references = $entity->getUseReferences();
            $entityReferences = array(
                'entity' => $entity,
                'references' => array()
            );
            if (!empty($references)) {
                foreach ($references as $type => $reference) {
                    if (in_array($type, $supportedEntities)) {
                        $referenceIds = array_keys($reference);
                        $repo = $this->getRepositoryByType($type);
                        foreach ($referenceIds as $referenceId) {
                            $referenceEntity = $repo->findById($referenceId);
                            if (
                                $siteId !== $referenceEntity->getSiteId()
                            ) {
                                $entityReferences['references'][$type][$referenceEntity->getId()] = $referenceEntity;
                            }
                        }
                    }
                }
                $usedOtherSite[] = $entityReferences;
            }
        }

        return $usedOtherSite;
    }
749924
protected function waitForSite($site_id)
    {
        return $this->retry(50, function () use ($site_id) {
            $this->sites = $this->fetchSites(fp_env('ACACHA_FORGE_SERVER'));
            $site = $this->getSite($this->sites, $site_id);
            return $site->status == 'installed' ? $site : null;
        });
    }
1295203
public static function cache( int $id )
	{
		if( ! self::cacheIs($id) && $id === 0 )
		{
			$module = new ModuleCore();
			self::setCache(0, $module->setLoadedFromCache());
		}

		return self::defaultCache($id);
	}