Skip to content

Commit

Permalink
Remove cache tags -> incompatible with redis
Browse files Browse the repository at this point in the history
  • Loading branch information
cannycookie committed Dec 19, 2024
1 parent 4c9f433 commit 665ec38
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions config/filament-user-consent.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php


use Visualbuilder\FilamentUserConsent\Models\ConsentOption;

return [

//To which authenticatable models consents should be applied?
Expand Down
6 changes: 3 additions & 3 deletions src/Models/ConsentOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ protected static function booted()
if ($consentOption->isDirty('is_current') && $consentOption->is_current) {
$consentOption->setCurrentVersion();
}
Cache::tags(['user-consents'])->flush();
Cache::flush();
});

// Handle the deleted event
static::deleted(function ($consentOption) {
Cache::tags(['user-consents'])->flush();
Cache::flush();
});
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public static function activeKeysForUser($user): array
{
$className = class_basename($user);
$cacheKey = 'consent_option_active_keys_for_'.$className.'_'.$user->id;
return Cache::tags(['user-consents'])->rememberForever($cacheKey, function () use ($user, $className) {
return Cache::rememberForever($cacheKey, function () use ($user, $className) {
return self::where('models', 'like', "%$className%")
->where('is_current', true)
->where('enabled', true)
Expand Down
14 changes: 2 additions & 12 deletions src/Models/ConsentOptionUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,8 @@ public static function clearCache($consentOptionUser)
$userKey = class_basename($consentOptionUser->consentable_type).'_'.$consentOptionUser->consentable_id;
$cacheKey1 = 'consent_option_active_keys_for_'.$userKey;
$cacheKey2 = 'user_consent_'.$userKey;

// Similarly, flush the cache when a consent option user relationship is deleted
// Flush the cache for the specific user involved using a simplified class name
Cache::tags([
'user-consents',
$cacheKey1
])->flush();

Cache::tags([
'user-consents',
$cacheKey2
])->flush();
Cache::forget($cacheKey1);
Cache::forget($cacheKey2);
}

public static function getAllSavedUserTypes(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasConsent.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function hasRequiredConsents()
$cacheKey = 'user_consent_'.class_basename($this).'_'.$this->getKey();

// Retrieve from cache or calculate if not cached
return Cache::tags(['user-consents'])->rememberForever($cacheKey, function () {
return Cache::rememberForever($cacheKey, function () {
$consentOptionModel = config('filament-user-consent.models.consent_option');
$requiredConsents = $consentOptionModel::findbykeys($this->requiredConsentKeys())
->where('force_user_update', true)
Expand Down

0 comments on commit 665ec38

Please sign in to comment.