Fixes caching to actually clear the cache for *all* users, rather than the logged in user by using cache tags.

This commit is contained in:
Dane Everitt 2017-03-04 19:24:46 -05:00
parent 5d59d364f8
commit cd0a45a777
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 12 additions and 7 deletions

View file

@ -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.

View file

@ -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);
});

View file

@ -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:<uuid>
* 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));
}