Skip to content

Commit 2292a37

Browse files
authored
Merge pull request #73 from hscstack/fix/node-cache-issue
fix: clear node cache on CRUD
2 parents 1150987 + e2a2b5c commit 2292a37

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎app/Observers/NodeObserver.php‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ class NodeObserver
1010
{
1111
public function created(Node $node): void
1212
{
13-
if ($node->parent_id === null) {
14-
CacheHelper::clearHomePage();
15-
}
13+
$this->clearNodeCache($node);
14+
}
15+
16+
public function updated(Node $node): void
17+
{
18+
$this->clearNodeCache($node);
1619
}
1720

1821
public function deleted(Node $node): void
1922
{
23+
$this->clearNodeCache($node);
24+
}
25+
26+
private function clearNodeCache(Node $node): void
27+
{
28+
Cache::forget("node_children_{$node->id}");
29+
Cache::forget("node_resources_{$node->id}");
30+
Cache::forget("node_breadcrumb_{$node->id}");
31+
32+
if ($node->parent_id) {
33+
Cache::forget("node_children_{$node->parent_id}");
34+
}
35+
2036
if ($node->parent_id === null) {
2137
CacheHelper::clearHomePage();
2238
}

0 commit comments

Comments
 (0)