mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.22k stars 212 forks source link

Only flush cache when delete() returns a count #435

Open m-lotze opened 1 year ago

m-lotze commented 1 year ago

The two methods delete and forceDelete in Buildable trait should imho only flush the cache, if the parent methods return an int > 0. Right now, the cache is flushed every time, even when the query did not actually deleted records from the database.

public function delete()
{
    $result = parent::delete();

    if ($result) {
        $this->cache($this->makeCacheTags())->flush();
    }

    return $result;
}