Skip to content

Commit

Permalink
Cache topic cache (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Jan 23, 2024
1 parent 4adeb4f commit 0371a78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Models/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EscolaLms\Courses\Models;

use Chelout\RelationshipEvents\Concerns\HasMorphToManyEvents;
use EscolaLms\Core\Models\Traits\QueryCacheable;
use EscolaLms\Courses\Database\Factories\TopicFactory;
use EscolaLms\Courses\Facades\Topic as TopicFacade;
Expand Down Expand Up @@ -207,4 +208,11 @@ public function getIsActiveAttribute(): bool
{
return $this->active && ($this->course ? $this->course->is_active : true);
}

protected function getCacheBaseTags(): array
{
return [
Topic::class,
];
}
}
7 changes: 7 additions & 0 deletions src/Observers/TopicObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public function creating(Topic $topic)

public function saved(Topic $topic)
{
Topic::flushQueryCache();
ResponseCache::clear();
}

public function deleted(Topic $topic)
{
Topic::flushQueryCache();
ResponseCache::clear();
}
}

0 comments on commit 0371a78

Please sign in to comment.