src/PeskyCMF/Db/Traits/TaggedCacheForDbSelects.php
public function cleanRelatedModelsCache($cleanRelatedModelsCache = true) {
        /** @var CmfDbTable|TaggedCacheForDbSelects $this */
        if ($cleanRelatedModelsCache === null) {
            $cleanRelatedModelsCache = $this->canCleanRelationsCache();
        }
        if ($cleanRelatedModelsCache) {
            if (is_array($cleanRelatedModelsCache)) {
                $relationsToClean = $cleanRelatedModelsCache;
            } else if (is_string($cleanRelatedModelsCache)) {
                $relationsToClean = [$cleanRelatedModelsCache];
            } else {
                $relationsToClean = $this->getDefaultRelationsForCacheCleaner();
            }
            $tags = [];
            foreach ($relationsToClean as $relationKey) {
                if (!$this->hasTableRelation($relationKey)) {
                    throw new \InvalidArgumentException("Model has no relation named $relationKey");
                }
                /** @var CmfDbTable|TaggedCacheForDbSelects $model */
                $model = $this->getRelatedModel($relationKey);
                $tags[] = $model->getModelCachePrefix();
            }
            if (!empty($tags)) {
                \Cache::tags($tags)->flush();
            }
        }
    }
public function cleanRelatedModelsCache($cleanRelatedModelsCache = true) {
        /** @var CmfDbTable|TaggedCacheForDbSelects $this */
        if ($cleanRelatedModelsCache === null) {
            $cleanRelatedModelsCache = $this->canCleanRelationsCache();
        }
        if ($cleanRelatedModelsCache) {
            if (is_array($cleanRelatedModelsCache)) {
                $relationsToClean = $cleanRelatedModelsCache;
            } else if (is_string($cleanRelatedModelsCache)) {
                $relationsToClean = [$cleanRelatedModelsCache];
            } else {
                $relationsToClean = $this->getDefaultRelationsForCacheCleaner();
            }
            $tags = [];
            foreach ($relationsToClean as $relationKey) {
                if (!$this->hasTableRelation($relationKey)) {
                    throw new \InvalidArgumentException("Model has no relation named $relationKey");
                }
                /** @var CmfDbTable|TaggedCacheForDbSelects $model */
                $model = $this->getRelatedModel($relationKey);
                $tags[] = $model->getModelCachePrefix();
            }
            if (!empty($tags)) {
                \Cache::tags($tags)->flush();
            }
        }
    }
public function cleanRelatedModelsCache ( $ cleanRelatedModelsCache = true ) { /** @var CmfDbTable|TaggedCacheForDbSelects $this */ if ( $ cleanRelatedModelsCache === null ) { $ cleanRelatedModelsCache = $ this -> canCleanRelationsCache ( ) ; } if ( $ cleanRelatedModelsCache ) { if ( is_array ( $ cleanRelatedModelsCache ) ) { $ relationsToClean = $ cleanRelatedModelsCache ; } else if ( is_string ( $ cleanRelatedModelsCache ) ) { $ relationsToClean = [ $ cleanRelatedModelsCache ] ; } else { $ relationsToClean = $ this -> getDefaultRelationsForCacheCleaner ( ) ; } $ tags = [ ] ; foreach ( $ relationsToClean as $ relationKey ) { if ( ! $ this -> hasTableRelation ( $ relationKey ) ) { throw new \ InvalidArgumentException ( "Model has no relation named $relationKey" ) ; } /** @var CmfDbTable|TaggedCacheForDbSelects $model */ $ model = $ this -> getRelatedModel ( $ relationKey ) ; $ tags [ ] = $ model -> getModelCachePrefix ( ) ; } if ( ! empty ( $ tags ) ) { \ Cache :: tags ( $ tags ) -> flush ( ) ; } } }
Clean cache for all related models
@param bool|null|array|string $cleanRelatedModelsCache -
- array: list of relations to clean
- string: single relation to clean
- bool: true = clean all relations provided by $this->getRelationsToCleanByDefault(); false - don't clean relations
- null: if ($this->canCleanRelationsCache() === true) then clean $this->getRelationsToCleanByDefault()

@throws \BadMethodCallException
@throws \PeskyORM\Exception\DbConnectionConfigException
@throws \PeskyORM\Exception\DbModelException
@throws \PeskyORM\Exception\DbUtilsException
@throws \InvalidArgumentException
@throws \PeskyORM\Exception\DbTableConfigException
Clean cache for all related models @param bool|null|array|string $cleanRelatedModelsCache - - array : list of relations to clean - string : single relation to clean - bool : true = clean all relations provided by $this - > getRelationsToCleanByDefault () ; false - don t clean relations - null : if ( $this - > canCleanRelationsCache () === true ) then clean $this - > getRelationsToCleanByDefault ()