Skip to content

flushCacheOnUpdate does not clear cache for Builder update() / delete() calls #241

@baaslaawe

Description

@baaslaawe

Description

When using QueryCacheable with:

use Rennokki\QueryCache\Traits\QueryCacheable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
use QueryCacheable;

protected static $flushCacheOnUpdate = true;
protected $cacheFor = 300;

}

cache is flushed for model instance operations, but not for Builder operations.

Steps to reproduce
// 1) Warm cache
Post::where('user_id', 1)->get();
Post::where('user_id', 1)->get(); // served from cache

// 2) Modify using Builder
Post::where('user_id', 1)->update(['title' => 'Changed']);
// or: Post::where('user_id', 1)->delete();

// 3) Same query again
$posts = Post::where('user_id', 1)->get();

Result: $posts still comes from cache and does not reflect the update/delete until TTL expires or Post::flushQueryCache() is called manually.

Instance operations work as expected:

$post = Post::first();
$post->update(['title' => 'Changed']); // cache flushed
$post->delete(); // cache flushed

Expected

Either:

flushCacheOnUpdate also flushes cache after where()->update() / where()->delete(), or

Docs clearly state that it only applies to model instance events and not to Builder operations.

Question

Is this behavior (no flush for Builder update/delete) intentional?
If yes, can the docs mention this explicitly, or provide a recommended pattern for auto-flushing after bulk Builder operations?

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