rememberable icon indicating copy to clipboard operation
rememberable copied to clipboard

flush morphToMany not working

Open hen3b182 opened this issue 4 years ago • 3 comments

Project.php

class Project extends Model
{	
    use Rememberable;

    public $rememberCacheTag = 'project_queries';
    public $rememberFor = 60*60*24;
	
    public function users()
    {
        return $this->morphToMany(User::class, 'model','model_has_users');
    }

User.php

class User extends Authenticatable
    {
        use Rememberable;
    
        public $rememberCacheTag = 'user_queries';
        public $rememberFor = 60*60*24;
        
    public function projects()
    {
        return $this->hasMany(Project::class);
    }

Now this works:

Cache::flush();

And this does not:

Project::flushCache('project_queries');

Project::find(1)->name (refreshed) Project::find(1)->users (not refreshed)

help!?

hen3b182 avatar Jul 08 '20 14:07 hen3b182

Wouldn't you want to flush the user_queries cache in this instance?

There's some known issues regarding caching with morph relationships. Happy to review any code that seeks to resolve the problems.

dwightwatson avatar Jul 09 '20 01:07 dwightwatson

Wouldn't you want to flush the user_queries cache in this instance?

There's some known issues regarding caching with morph relationships. Happy to review any code that seeks to resolve the problems.

Do I have to flush both cache tags in this case? And all other morph relations?

hen3b182 avatar Jul 09 '20 05:07 hen3b182

Yeah, I'd assume so. But there are a few open issues around morphing relationships, so no guarantees this will work as you expect.

dwightwatson avatar Jul 09 '20 05:07 dwightwatson