Skip to content

How to invalidate Model cache | Phalcon 4 #16310

@shafikhaan

Description

@shafikhaan

I've the following to cache model query and it is working fine,

public static function getSubcategories($partnerId)
    {
        $instance = new self();
        $q =  $instance->modelsManager->createBuilder();
        $q = $q->columns([
                        'cc.category',
                        'cc.type',
                        'cc.slug',
                        'cc.title',
                    ])
                    ->from(['cc' => CatalogCategories::class])
                    ->join(PartnerTypes::class, 'cc.category = pt.typeSlug', 'pt')
                    ->where('pt.parentId = :partnerId:', compact('partnerId'));
        $cacheKey = 'getSubcategories';
        if ($partnerId) {
            $cacheKey .= '_' . $partnerId;
        }
        $q = $q->getQuery();
        if($instance->getDI()->get('config')->cache->isEnabled){
            $q = $q->cache(
                [
                    'key'      => $cacheKey,
                    'lifetime' => $instance->getDI()->get('config')->cache->duration->min15,
                ]
            );
        }
        return $q->execute();
    }

But how to invalidate cache with a key, i've read the documentation but couldn't find anything how to invalidate the cache with a key?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions