改进 清理缓存

This commit is contained in:
iVampireSP.com 2022-10-28 16:22:45 +08:00
parent e122c41448
commit 1730f8a474
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -198,6 +198,7 @@ protected static function boot()
static::created(function ($model) { static::created(function ($model) {
broadcast(new UserEvent($model->user_id, 'hosts.created', $model)); broadcast(new UserEvent($model->user_id, 'hosts.created', $model));
Cache::forget('user_tasks_' . $model->user_id);
}); });
static::updating(function ($model) { static::updating(function ($model) {
@ -206,6 +207,8 @@ protected static function boot()
} else if ($model->status == 'running') { } else if ($model->status == 'running') {
$model->suspended_at = null; $model->suspended_at = null;
} }
Cache::forget('user_tasks_' . $model->user_id);
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model)); broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
}); });
@ -215,6 +218,8 @@ protected static function boot()
dispatch(new \App\Jobs\Remote\Host($model, 'patch')); dispatch(new \App\Jobs\Remote\Host($model, 'patch'));
Cache::forget('user_hosts_' . $model->user_id); Cache::forget('user_hosts_' . $model->user_id);
Cache::forget('user_tasks_' . $model->user_id);
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model)); broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
}); });
@ -224,9 +229,13 @@ protected static function boot()
// broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model)); // broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model));
// }); // });
static::deleting(function ($model) {
Cache::forget('user_tasks_' . $model->user_id);
});
static::deleted(function ($model) { static::deleted(function ($model) {
broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model)); broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model));
Cache::forget('user_tasks_' . $model->user_id);
Cache::forget('user_hosts_' . $model->user_id); Cache::forget('user_hosts_' . $model->user_id);
}); });
} }