fix: 🐛 set getCacheKey from cache trait private
This commit is contained in:
parent
d0640dc770
commit
87b54071cb
1 changed files with 12 additions and 19 deletions
|
|
@ -19,16 +19,6 @@ trait HasCache
|
|||
*/
|
||||
public static function bootHasCache(): void
|
||||
{
|
||||
$hadSoftDelete = method_exists(static::class, 'initializeSoftDeletes');
|
||||
|
||||
if ($hadSoftDelete) {
|
||||
static::restored(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
static::forceDeleted(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
static::created(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
|
|
@ -38,6 +28,14 @@ trait HasCache
|
|||
static::deleted(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
if (method_exists(static::class, 'initializeSoftDeletes')) {
|
||||
static::restored(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
static::forceDeleted(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,11 +45,7 @@ trait HasCache
|
|||
*/
|
||||
public static function resetCache(): void
|
||||
{
|
||||
$class = static::class;
|
||||
$cacheKey = static::getCacheKey();
|
||||
|
||||
Cache::forget($cacheKey);
|
||||
|
||||
Cache::forget(static::getCacheKey());
|
||||
static::getModelsCached();
|
||||
}
|
||||
|
||||
|
|
@ -62,10 +56,9 @@ trait HasCache
|
|||
*/
|
||||
public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
$class = static::class;
|
||||
$cacheKey = static::getCacheKey();
|
||||
return Cache::remember(static::getCacheKey(), 86400, function () {
|
||||
$class = static::class;
|
||||
|
||||
return Cache::remember($cacheKey, 86400, function () use ($class) {
|
||||
/** @var \Illuminate\Database\Eloquent\Model $class */
|
||||
return $class::query()
|
||||
->when(property_exists($class, 'cacheRelations') && is_array($class::$cacheRelations), function ($query) use ($class) {
|
||||
|
|
@ -80,7 +73,7 @@ trait HasCache
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getCacheKey(): string
|
||||
private static function getCacheKey(): string
|
||||
{
|
||||
return 'cache_' . str_replace('\\', '_', static::class);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue