Просмотр исходного кода

#5269 Content cache should include lang in key name

Alex Trofimov 11 месяцев назад
Родитель
Сommit
ee7d9caacf
1 измененных файлов с 18 добавлено и 11 удалено
  1. 18 11
      inc/utils.inc.php

+ 18 - 11
inc/utils.inc.php

@@ -2823,37 +2823,44 @@ function bx_get_context_workspace($bFromCache = true)
     return ($GLOBALS['bxWorkspaceContext'] = array_pop($a));
     return ($GLOBALS['bxWorkspaceContext'] = array_pop($a));
 }
 }
 
 
-function bx_content_cache_get($sKey, $iTTL = false)
+function bx_content_cache_get(string $sKey, int|false $iTTL = false): mixed
 {
 {
     if (!getParam('sys_content_cache_enable'))
     if (!getParam('sys_content_cache_enable'))
         return null;
         return null;
 
 
     $oCache = bx_content_cache_obj();
     $oCache = bx_content_cache_obj();
-    return $oCache->getData('content_' . $sKey . '_' . bx_site_hash() . '.php', $iTTL);
+    return $oCache->getData(bx_content_cache_key($sKey), $iTTL);
 }
 }
 
 
-function bx_content_cache_set($sKey, $mixedData, $iTTL = false)
+function bx_content_cache_set(string $sKey, mixed $mixedData, int|false $iTTL = false): bool
 {
 {
     if (!getParam('sys_content_cache_enable'))
     if (!getParam('sys_content_cache_enable'))
         return false;
         return false;
 
 
     $oCache = bx_content_cache_obj();
     $oCache = bx_content_cache_obj();
-    return $oCache->setData('content_' . $sKey . '_' . bx_site_hash() . '.php', $mixedData, $iTTL);
+    return (bool)$oCache->setData(bx_content_cache_key($sKey), $mixedData, $iTTL);
 }
 }
 
 
-function bx_content_cache_del($sKey)
+function bx_content_cache_del(string $sKey): bool
 {
 {
     $oCache = bx_content_cache_obj();
     $oCache = bx_content_cache_obj();
-    return $oCache->delData('content_' . $sKey . '_' . bx_site_hash() . '.php');
+    return (bool)$oCache->delData(bx_content_cache_key($sKey));
 }
 }
 
 
-function bx_content_cache_del_by_prefix($sPrefix)
+function bx_content_cache_del_by_prefix(string $sPrefix): bool
 {
 {
     $oCache = bx_content_cache_obj();
     $oCache = bx_content_cache_obj();
-    return $oCache->removeAllByPrefix('content_' . $sPrefix);
+    return (bool)$oCache->removeAllByPrefix(bx_content_cache_key($sPrefix, true));
 }
 }
 
 
-function bx_content_cache_obj()
+function bx_content_cache_key(string $sKey, bool $bPrefixOnly = false): string
+{
+    if ($bPrefixOnly)
+        return 'content_' . $sKey;
+    return 'content_' . $sKey . '_' . bx_lang_name() . '_' . bx_site_hash() . '.php';
+}
+
+function bx_content_cache_obj(): object
 {
 {
     if (isset($GLOBALS['bxCacheContentObj']))
     if (isset($GLOBALS['bxCacheContentObj']))
         return $GLOBALS['bxCacheContentObj'];
         return $GLOBALS['bxCacheContentObj'];
@@ -2866,7 +2873,7 @@ function bx_content_cache_obj()
     return $GLOBALS['bxCacheContentObj'] = $oCacheObject;
     return $GLOBALS['bxCacheContentObj'] = $oCacheObject;
 }
 }
 
 
-function bx_mem_cache_get($sKey)
+function bx_mem_cache_get(string $sKey): mixed
 {
 {
     if(isset($GLOBALS['glMemCache']) && array_key_exists($sKey, $GLOBALS['glMemCache']) && !defined('BX_DOL_INSTALL') && !defined('BX_DOL_CRON_EXECUTE'))
     if(isset($GLOBALS['glMemCache']) && array_key_exists($sKey, $GLOBALS['glMemCache']) && !defined('BX_DOL_INSTALL') && !defined('BX_DOL_CRON_EXECUTE'))
         return $GLOBALS['glMemCache'][$sKey];
         return $GLOBALS['glMemCache'][$sKey];
@@ -2874,7 +2881,7 @@ function bx_mem_cache_get($sKey)
     return null;
     return null;
 }
 }
 
 
-function bx_mem_cache_set($sKey, $mixedData)
+function bx_mem_cache_set(string $sKey, mixed $mixedData): mixed
 {
 {
     if(!isset($GLOBALS['glMemCache']))
     if(!isset($GLOBALS['glMemCache']))
         $GLOBALS['glMemCache'] = [];
         $GLOBALS['glMemCache'] = [];