You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using laravel response cache recently for my website and it works great. But recently I had a problem where I had to clear the cache for a uri when the model associated with that uri changed. As follows:
When a user comments on a post, I want to clear the cache for that post for everyone visiting the site. I do it by handling the change event that creates the comment model as follows:
`public static function boot()
{
parent::boot();
static::saved(function ($model) {
$post = $model->post;
ResponseCache::selectCachedItems()->forUrls(route('post_detail', $post->slug))->forget();
});
}`
When I test it locally it works fine. But when posting to a website with a lot of different users, it seems that clearing this cache is not done for some users and sometimes for users who are not logged in. This has me trying to figure out for days but still haven't found a solution. I would be very grateful if someone could help me with this!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've been using laravel response cache recently for my website and it works great. But recently I had a problem where I had to clear the cache for a uri when the model associated with that uri changed. As follows:
When a user comments on a post, I want to clear the cache for that post for everyone visiting the site. I do it by handling the change event that creates the comment model as follows:
`public static function boot()
{
parent::boot();
static::saved(function ($model) {
$post = $model->post;
ResponseCache::selectCachedItems()->forUrls(route('post_detail', $post->slug))->forget();
When I test it locally it works fine. But when posting to a website with a lot of different users, it seems that clearing this cache is not done for some users and sometimes for users who are not logged in. This has me trying to figure out for days but still haven't found a solution. I would be very grateful if someone could help me with this!
Beta Was this translation helpful? Give feedback.
All reactions