Skip to content

Commit

Permalink
Added Cache clear after update or delete template
Browse files Browse the repository at this point in the history
  • Loading branch information
cannycookie committed Aug 26, 2024
1 parent 23e3b0e commit 9a95d3f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ public function __construct(array $attributes = [])
$this->setTableFromConfig();
}

protected static function boot()
{
parent::boot();

// When an email template is updated
static::updated(function ($template) {
self::clearEmailTemplateCache($template->key, $template->language);
});

// When an email template is deleted
static::deleted(function ($template) {
self::clearEmailTemplateCache($template->key, $template->language);
});
}

public function setTableFromConfig()
{
$this->table = config('filament-email-templates.table_name');
Expand All @@ -99,6 +114,12 @@ public static function findEmailByKey($key, $language = null)
});
}

public static function clearEmailTemplateCache($key, $language)
{
$cacheKey = "email_by_key_{$key}_{$language}";
Cache::forget($cacheKey);
}

/**
* @return \Illuminate\Support\Collection
*/
Expand Down

0 comments on commit 9a95d3f

Please sign in to comment.