diff --git a/config/module.config.php b/config/module.config.php index 0aedaf5..045dc32 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -298,5 +298,19 @@ // 'my_cache_key' => 60, ] ], + 'melisfront_memory_cache' => [ + 'active' => true, // activate or deactivate Melis Cache for this conf + 'adapter' => [ + 'name' => 'Memory', + 'options' => ['ttl' => 0, 'namespace' => 'melisfront'], + ], + 'plugins' => [ + 'exception_handler' => ['throw_exceptions' => false], + ], + 'ttls' => [ + // add a specific ttl for a specific cache key (found via regexp] + // 'my_cache_key' => 60, + ] + ], ] ]; diff --git a/src/Service/MelisTranslationService.php b/src/Service/MelisTranslationService.php index c05d276..bc57c43 100644 --- a/src/Service/MelisTranslationService.php +++ b/src/Service/MelisTranslationService.php @@ -23,6 +23,13 @@ class MelisTranslationService extends MelisGeneralService */ public function getTranslationsByLocale($locale = "en_EN") { + // Retrieve cache version if front mode to avoid multiple calls + $cacheKey = 'getTranslationsByLocale_' . $locale; + $cacheConfig = 'melisfront_memory_cache'; + $melisEngineCacheSystem = $this->getServiceManager()->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig, true); + if (!is_null($results)) + return $results; $moduleSvc = $this->getServiceManager()->get('MelisAssetManagerModulesService'); // Event parameters prepare @@ -78,11 +85,16 @@ public function getTranslationsByLocale($locale = "en_EN") } } } + // results $arrayParameters['results'] = $transMessages; + // send event $arrayParameters = $this->sendEvent('melis_translation_get_trans_by_locale_end', $arrayParameters); + // Save cache key + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $arrayParameters['results'], true); + return $arrayParameters['results']; }