diff --git a/CHANGELOG.md b/CHANGELOG.md index 919efdcb8..bd7eee349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * Fixes potential bug with invalid CIDR notation (ex: `192.168.1.1/z`) when adding allocations that could cause over 4 million records to be created at once. * `[pre.4]` — Fixes bug preventing server updates from occurring by the system due to undefined `Auth::user()` in the event listener. +* `[pre.4]` — Fixes `Server::byUuid()` caching to actually clear the cache for *all* users, rather than the logged in user by using cache tags. ### Added * Ability to assign multiple allocations at once when creating a new server. diff --git a/app/Models/Server.php b/app/Models/Server.php index 252646ba9..de85c45cc 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -26,6 +26,7 @@ namespace Pterodactyl\Models; use Auth; use Cache; +use Carbon; use Javascript; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; @@ -113,7 +114,7 @@ class Server extends Model public static function byUuid($uuid) { // Results are cached because we call this functions a few times on page load. - $result = Cache::remember('Server.byUuid.' . $uuid . Auth::user()->uuid, 60, function () use ($uuid) { + $result = Cache::tags(['Model:Server', 'Model:Server:byUuid:' . $uuid])->remember('Model:Server:byUuid:' . $uuid . Auth::user()->uuid, Carbon::now()->addMinutes(15), function () use ($uuid) { $query = self::with('service', 'node')->where(function ($q) use ($uuid) { $q->where('uuidShort', $uuid)->orWhere('uuid', $uuid); }); diff --git a/app/Observers/ServerObserver.php b/app/Observers/ServerObserver.php index 973b276d2..554e86a82 100644 --- a/app/Observers/ServerObserver.php +++ b/app/Observers/ServerObserver.php @@ -24,7 +24,6 @@ namespace Pterodactyl\Observers; -use Auth; use Cache; use Carbon; use Pterodactyl\Events; @@ -141,11 +140,15 @@ class ServerObserver */ public function updated(Server $server) { - // Clear Caches - if (Auth::user()) { - Cache::forget('Server.byUuid.' . $server->uuid . Auth::user()->uuid); - Cache::forget('Server.byUuid.' . $server->uuidShort . Auth::user()->uuid); - } + /** + * The cached byUuid model calls are tagged with Model:Server:byUuid: + * so that they can be accessed regardless of if there is an Auth::user() + * defined or not. + * + * We can also delete all cached byUuid items using the Model:Server tag. + */ + Cache::tags('Model:Server:byUuid:' . $server->uuid)->flush(); + Cache::tags('Model:Server:byUuid:' . $server->uuidShort)->flush(); event(new Events\Server\Updated($server)); }