Skip to content

Commit

Permalink
chore: menu cache now supports multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Oct 7, 2024
1 parent 8106027 commit cde8ad1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions classes/StaticPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ public function canRestore(): bool {
* @return void
*/
public function clearMenuCache(): void {
elgg_delete_system_cache("static_menu_item_cache_{$this->guid}");
$languages = elgg()->translator->getAllowedLanguages();
foreach ($languages as $language) {
elgg_delete_system_cache("static_menu_item_cache_{$this->guid}_{$language}");
}
}

/**
Expand All @@ -150,7 +153,8 @@ public function clearMenuCache(): void {
* @return void
*/
public function saveMenuCache($contents): void {
elgg_save_system_cache("static_menu_item_cache_{$this->guid}", $contents);
$current_language = elgg_get_current_language();
elgg_save_system_cache("static_menu_item_cache_{$this->guid}_{$current_language}", $contents);
}

/**
Expand All @@ -159,7 +163,8 @@ public function saveMenuCache($contents): void {
* @return mixed
*/
public function getMenuCache() {
return elgg_load_system_cache("static_menu_item_cache_{$this->guid}");
$current_language = elgg_get_current_language();
return elgg_load_system_cache("static_menu_item_cache_{$this->guid}_{$current_language}");
}

/**
Expand All @@ -171,6 +176,19 @@ public function getFriendlyTitle(): string {
return $this->friendly_title ?: static_make_friendly_title($this->title);
}

/**
* {@inheritdoc}
*/
public function invalidateCache(): void {
if (!$this->guid) {
return;
}

parent::invalidateCache();

$this->getRootPage()->clearMenuCache();
}

/**
* Returns the root page of an entity
*
Expand Down

0 comments on commit cde8ad1

Please sign in to comment.