rememberable
rememberable copied to clipboard
flush morphToMany not working
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!?
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.
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?
Yeah, I'd assume so. But there are a few open issues around morphing relationships, so no guarantees this will work as you expect.