Caches the super and sub relationships by doing a prefetch_related.
971678
def cache_relationships(self, cache_super=True, cache_sub=True):
        
        return self.get_queryset().cache_relationships(cache_super=cache_super, cache_sub=cache_sub)
1271462
public static void clearCaches()
    {
        synchronized (AbstractCache.CACHES) {
            for (final AbstractCache<?> cache : AbstractCache.CACHES) {
                cache.getCache4Id().clear();
                cache.getCache4Name().clear();
                cache.getCache4UUID().clear();
            }
        }
    }
53673
def _build(self, parent_cache):
        
        for key, mice in parent_cache.cache.items():
            if not mice.damaged_by_cut(self.subsystem):
                self.cache[key] = mice
255610
final private function prefetch() {
        static $prefetched = false;
        if(!$prefetched) {
            $prefetched = true;
            while($row = $this->doFetch()) $this->prefetched[] = $row;
        }
    }
187590
protected function cacheSingleRelationResult(string $parentKey, string $relation, $result, Relationship $relationship)
    {
        $this->cache[$parentKey][$relation] = $this->getCachedRelationship($relation, $result, $relationship);
    }
471953
@Override
	public void cacheResult(
		List<CommerceTierPriceEntry> commerceTierPriceEntries) {
		for (CommerceTierPriceEntry commerceTierPriceEntry : commerceTierPriceEntries) {
			if (entityCache.getResult(
						CommerceTierPriceEntryModelImpl.ENTITY_CACHE_ENABLED,
						CommerceTierPriceEntryImpl.class,
						commerceTierPriceEntry.getPrimaryKey()) == null) {
				cacheResult(commerceTierPriceEntry);
			}
			else {
				commerceTierPriceEntry.resetOriginalValues();
			}
		}
	}
144011
private void putInCache(MembershipType mt)
   {
      cache.put(mt.getName(), mt, CacheType.MEMBERSHIPTYPE);
   }
1062217
protected function attachRelatedPiecesAfterSave()
    {
        if (isset($this->related_data['settings']) && is_array($this->related_data['settings']) && count($this->related_data['settings']) > 0) {
            foreach ($this->related_data['settings'] as $setting) {

                $contextSetting = $this->modx->getObject('modContextSetting', ['context_key' => $this->getFieldKey(), 'key' => $setting['key']]);
                if (!is_object($contextSetting)) {
                    $contextSetting = $this->modx->newObject('modContextSetting');
                }
                $contextSetting->fromArray($setting);
                $contextSetting->set('context_key', $this->getFieldKey());
                $contextSetting->set('key', $setting['key']);
                $contextSetting->set('value', $this->convertToLocalData($setting));
                $contextSetting->save();
            }
        }

        foreach ($this->remove_settings as $setting_key) {

            $contextSetting = $this->modx->getObject('modContextSetting', ['context_key' => $this->getFieldKey(), 'key' => $setting_key]);
            if (is_object($contextSetting)) {
                $contextSetting->remove();
            }
        }
    }
658071
private void preloadDynamicCaches() {
        List<CacheService> dynamicCacheServices = CacheRegistry.getInstance().getDynamicCacheServices();
        for (CacheService dynamicCacheService : dynamicCacheServices) {
            if (dynamicCacheService instanceof PreloadableCache) {
                try {
                    PreloadableCache preloadableCache = (PreloadableCache)dynamicCacheService;
                    RegisteredService regServ = preloadableCache.getClass().getAnnotation(RegisteredService.class);
                    Map<String,String> params = new HashMap<>();
                    Parameter[] parameters = regServ.parameters();
                    if (parameters != null) {
                        for (Parameter parameter : parameters) {
                            if (parameter.name().length() > 0)
                                params.put(parameter.name(), parameter.value());
                        }
                    }
                    preloadableCache.initialize(params);
                    preloadableCache.loadCache();
                }
                catch (Exception ex) {
                    logger.severeException("Failed to preload " + dynamicCacheService.getClass(), ex);
                }
            }
            synchronized(allCaches) {
                allCaches.put(dynamicCacheService.getClass().getName(), dynamicCacheService);
            }
        }
    }
1023550
def _get_prefetched_translations(self, meta=None):
        
        if meta is None:
            meta = self._parler_meta.root

        related_name = meta.rel_name
        try:
            # Read the list directly, avoid QuerySet construction.
            # Accessing self._get_translated_queryset(parler_meta)._prefetch_done is more expensive.
            return self._prefetched_objects_cache[related_name]
        except (AttributeError, KeyError):
            return None
518242
protected function cacheManyRelationResults(string $parentKey, string $relation, $results, Relationship $relationship)
    {
        $this->cache[$parentKey][$relation] = [];

        foreach ($results as $result) {
            $cachedRelationship = $this->getCachedRelationship($relation, $result, $relationship);

            $relatedHash = $cachedRelationship->getHash();

            $this->cache[$parentKey][$relation][$relatedHash] = $cachedRelationship;
        }
    }
134100
async def prefetch(self, query, *subqueries):
        
        query = self._swap_database(query)
        subqueries = map(self._swap_database, subqueries)
        return (await prefetch(query, *subqueries))
355284
protected Query[] buildPrefetchQueries(Collection proxies, Collection realSubjects)
    {
        Collection queries = new ArrayList();
        Collection idsSubset;
        Object proxy;
        IndirectionHandler handler;
        Identity id;
        Class realClass;
        HashMap classToIds = new HashMap();
        Class topLevelClass = getItemClassDescriptor().getClassOfObject();
        PersistenceBroker pb = getBroker();
        ObjectCache cache = pb.serviceObjectCache();

        for (Iterator it = proxies.iterator(); it.hasNext(); )
        {
            proxy = it.next();
            handler = ProxyHelper.getIndirectionHandler(proxy);

            if (handler == null)
            {
                continue;
            }
            
            id = handler.getIdentity();
            if (cache.lookup(id) != null)
            {
                realSubjects.add(pb.getObjectByIdentity(id));
                continue;
            }
            realClass = id.getObjectsRealClass();
            if (realClass == null)
            {
                realClass = Object.class; // to remember that the real class is unknown
            }
            idsSubset = (HashSet) classToIds.get(realClass);
            if (idsSubset == null)
            {
                idsSubset = new HashSet();
                classToIds.put(realClass, idsSubset);
            }
            idsSubset.add(id);
            if (idsSubset.size() == pkLimit)
            {
                Query query;
                if (realClass == Object.class)
                {
                    query = buildPrefetchQuery(topLevelClass, idsSubset, true);
                }
                else
                {
                    query = buildPrefetchQuery(realClass, idsSubset, false);
                }
                queries.add(query);
                idsSubset.clear();
            }
        }

        for (Iterator it = classToIds.entrySet().iterator(); it.hasNext(); )
        {
            Map.Entry entry = (Map.Entry) it.next();
            realClass = (Class) entry.getKey();
            idsSubset = (HashSet) entry.getValue();
            if (idsSubset.size() > 0)
            {
                Query query;
                if (realClass == Object.class)
                {
                    query = buildPrefetchQuery(topLevelClass, idsSubset, true);
                }
                else
                {
                    query = buildPrefetchQuery(realClass, idsSubset, false);
                }
                queries.add(query);
            }
        }

        return (Query[]) queries.toArray(new Query[queries.size()]);
    }
567579
function prefetch()
    {
        $relatedObjectIDArray = array();
        $nodeIDArray = array();

        // Fetch all links and cache urls
        $linkIDArray = $this->getAttributeValueArray( 'link', 'url_id' );
        if ( count( $linkIDArray ) > 0 )
        {
            $inIDSQL = implode( ', ', $linkIDArray );

            $db = eZDB::instance();
            $linkArray = $db->arrayQuery( "SELECT * FROM ezurl WHERE id IN ( $inIDSQL ) " );

            foreach ( $linkArray as $linkRow )
            {
                $url = str_replace( '&', '&amp;', $linkRow['url'] );
                $this->LinkArray[$linkRow['id']] = $url;
            }
        }

        $linkRelatedObjectIDArray = $this->getAttributeValueArray( 'link', 'object_id' );
        $linkNodeIDArray = $this->getAttributeValueArray( 'link', 'node_id' );

        // Fetch all embeded objects and cache by ID
        $objectRelatedObjectIDArray = $this->getAttributeValueArray( 'object', 'id' );

        $embedRelatedObjectIDArray = $this->getAttributeValueArray( 'embed', 'object_id' );
        $embedInlineRelatedObjectIDArray = $this->getAttributeValueArray( 'embed-inline', 'object_id' );

        $embedNodeIDArray = $this->getAttributeValueArray( 'embed', 'node_id' );
        $embedInlineNodeIDArray = $this->getAttributeValueArray( 'embed-inline', 'node_id' );

        $relatedObjectIDArray = array_merge(
            $linkRelatedObjectIDArray,
            $objectRelatedObjectIDArray,
            $embedRelatedObjectIDArray,
            $embedInlineRelatedObjectIDArray );
        $relatedObjectIDArray = array_unique( $relatedObjectIDArray );

        if ( count( $relatedObjectIDArray ) > 0 )
        {
            if ( $this->ContentObjectAttribute instanceof eZContentObjectAttribute )
            {
                $this->ObjectArray = eZContentObject::fetchIDArray(
                    $relatedObjectIDArray, true,
                    $this->ContentObjectAttribute->attribute( 'language_code' )
                );
            }
            else
            {
                $this->ObjectArray = eZContentObject::fetchIDArray( $relatedObjectIDArray );
            }
        }

        $nodeIDArray = array_merge(
            $linkNodeIDArray,
            $embedNodeIDArray,
            $embedInlineNodeIDArray
        );
        $nodeIDArray = array_unique( $nodeIDArray );

        if ( count( $nodeIDArray ) > 0 )
        {
            $nodes = eZContentObjectTreeNode::fetch( $nodeIDArray );

            if ( is_array( $nodes ) )
            {
                foreach( $nodes as $node )
                {
                    $nodeID = $node->attribute( 'node_id' );
                    $this->NodeArray[$nodeID] = $node;
                }
            }
            elseif ( $nodes )
            {
                $node = $nodes;
                $nodeID = $node->attribute( 'node_id' );
                $this->NodeArray[$nodeID] = $node;
            }
        }
    }
920959
def load(self, *relations):
        
        if len(self.items) > 0:
            query = self.first().new_query().with_(*relations)

            self._set_items(query.eager_load_relations(self.items))

        return self
361681
public function beforeDelete()
    {
        /** @var BaseActiveRecord $owner */
        $owner = $this->owner;
        foreach ($this->_relationsCascadeDelete as $relationName => $params) {
            if ($params === true) {
                /** @var ActiveQuery $relation */
                $relation = $owner->getRelation($relationName);
                if (!empty($owner->{$relationName})) {
                    if ($relation->multiple === true) { // Has many relation
                        $this->_relationsToDelete = ArrayHelper::merge($this->_relationsToDelete, $owner->{$relationName});
                    } else {
                        $this->_relationsToDelete[] = $owner->{$relationName};
                    }
                }
            }
        }
    }
253613
private void recacheChildren()
        throws CacheReloadException
    {
        if (isDirty()) {
            Type.cacheType(this);
        }
        for (final Type child : getChildTypes()) {
            child.recacheChildren();
        }
    }