mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 20:49:20 +03:00
Better hash/cache handling for some functions
This commit is contained in:
parent
321782aa26
commit
85b06123c6
3 changed files with 16 additions and 35 deletions
|
|
@ -892,7 +892,7 @@ class Actions
|
|||
$aResult['userLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
||||
|
||||
$aResult['PluginsLink'] = $this->oPlugins->HaveJs($bAdmin)
|
||||
? 'Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $this->StaticCache() . '/'
|
||||
? 'Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $this->etag($this->oPlugins->Hash()) . '/'
|
||||
: '';
|
||||
|
||||
$bAppJsDebug = $this->oConfig->Get('debug', 'javascript', false)
|
||||
|
|
@ -1033,7 +1033,8 @@ class Actions
|
|||
|
||||
public function etag(string $sKey): string
|
||||
{
|
||||
return \md5($sKey . $this->oConfig->Get('cache', 'index', ''));
|
||||
// if ($sKey && $this->oConfig->Get('cache', 'enable', true) && $this->oConfig->Get('cache', 'http', true)) {
|
||||
return \md5($sKey . $this->oConfig->Get('cache', 'index', '') . APP_VERSION);
|
||||
}
|
||||
|
||||
public function cacheByKey(string $sKey): bool
|
||||
|
|
@ -1095,15 +1096,6 @@ class Actions
|
|||
*/
|
||||
}
|
||||
|
||||
public function StaticCache(): string
|
||||
{
|
||||
static $sCache = null;
|
||||
if (!$sCache) {
|
||||
$sCache = \md5(APP_VERSION . $this->oPlugins->Hash());
|
||||
}
|
||||
return $sCache;
|
||||
}
|
||||
|
||||
public function SetActionParams(array $aCurrentActionParams, string $sMethodName = ''): self
|
||||
{
|
||||
$this->oPlugins->RunHook('filter.action-params', array($sMethodName, &$aCurrentActionParams));
|
||||
|
|
|
|||
|
|
@ -184,8 +184,9 @@ abstract class Service
|
|||
|
||||
$sCacheFileName = '';
|
||||
if ($oConfig->Get('cache', 'system_data', true)) {
|
||||
$sCacheFileName = 'TMPL:' . $sLanguage . \sha1(
|
||||
$sCacheFileName = 'TMPL:' . \sha1(
|
||||
Utils::jsonEncode(array(
|
||||
$sLanguage,
|
||||
$oConfig->Get('cache', 'index', ''),
|
||||
$oActions->Plugins()->Hash(),
|
||||
$sAppJsMin,
|
||||
|
|
|
|||
|
|
@ -380,7 +380,6 @@ class ServiceActions
|
|||
|
||||
public function ServiceLang() : string
|
||||
{
|
||||
// sleep(2);
|
||||
$sResult = '';
|
||||
\header('Content-Type: application/javascript; charset=utf-8');
|
||||
|
||||
|
|
@ -389,27 +388,22 @@ class ServiceActions
|
|||
$sLanguage = $this->oActions->ValidateLanguage($this->aPaths[3], '', $bAdmin);
|
||||
|
||||
$bCacheEnabled = $this->Config()->Get('cache', 'system_data', true);
|
||||
if (!empty($sLanguage) && $bCacheEnabled) {
|
||||
$this->oActions->verifyCacheByKey($this->sQuery);
|
||||
}
|
||||
|
||||
$sCacheFileName = '';
|
||||
if ($bCacheEnabled) {
|
||||
$sCacheFileName = KeyPathHelper::LangCache(
|
||||
$sLanguage, $bAdmin, $this->oActions->Plugins()->Hash());
|
||||
|
||||
$sCacheFileName = KeyPathHelper::LangCache($sLanguage, $bAdmin, $this->oActions->Plugins()->Hash());
|
||||
$this->oActions->verifyCacheByKey(\md5($sCacheFileName));
|
||||
$sResult = $this->Cacher()->Get($sCacheFileName);
|
||||
}
|
||||
|
||||
if (!\strlen($sResult)) {
|
||||
$sResult = $this->oActions->compileLanguage($sLanguage, $bAdmin);
|
||||
if ($bCacheEnabled && \strlen($sCacheFileName)) {
|
||||
if ($sCacheFileName) {
|
||||
$this->Cacher()->Set($sCacheFileName, $sResult);
|
||||
}
|
||||
}
|
||||
|
||||
if ($bCacheEnabled) {
|
||||
$this->oActions->cacheByKey($this->sQuery);
|
||||
if ($sCacheFileName) {
|
||||
$this->oActions->cacheByKey(\md5($sCacheFileName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -427,13 +421,10 @@ class ServiceActions
|
|||
$sMinify = ($bAppDebug || $this->Config()->Get('debug', 'javascript', false)) ? '' : 'min';
|
||||
|
||||
$bCacheEnabled = !$bAppDebug && $this->Config()->Get('cache', 'system_data', true);
|
||||
if ($bCacheEnabled) {
|
||||
$this->oActions->verifyCacheByKey($this->sQuery . $sMinify);
|
||||
}
|
||||
|
||||
$sCacheFileName = '';
|
||||
if ($bCacheEnabled) {
|
||||
$sCacheFileName = KeyPathHelper::PluginsJsCache($this->oActions->Plugins()->Hash()) . $sMinify;
|
||||
$this->oActions->verifyCacheByKey(\md5($sCacheFileName));
|
||||
$sResult = $this->Cacher()->Get($sCacheFileName);
|
||||
}
|
||||
|
||||
|
|
@ -444,8 +435,8 @@ class ServiceActions
|
|||
}
|
||||
}
|
||||
|
||||
if ($bCacheEnabled) {
|
||||
$this->oActions->cacheByKey($this->sQuery . $sMinify);
|
||||
if ($sCacheFileName) {
|
||||
$this->oActions->cacheByKey(\md5($sCacheFileName));
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
|
|
@ -471,13 +462,10 @@ class ServiceActions
|
|||
$sMinify = ($bAppDebug || $this->Config()->Get('debug', 'css', false)) ? '' : 'min';
|
||||
|
||||
$bCacheEnabled = !$bAppDebug && $this->Config()->Get('cache', 'system_data', true);
|
||||
if ($bCacheEnabled) {
|
||||
$this->oActions->verifyCacheByKey($this->sQuery . $sMinify);
|
||||
}
|
||||
|
||||
$sCacheFileName = '';
|
||||
if ($bCacheEnabled) {
|
||||
$sCacheFileName = KeyPathHelper::CssCache($sTheme, $this->oActions->Plugins()->Hash()) . $sMinify;
|
||||
$this->oActions->verifyCacheByKey(\md5($sCacheFileName . ($bJson ? 1 : 0)));
|
||||
$sResult = $this->Cacher()->Get($sCacheFileName);
|
||||
}
|
||||
|
||||
|
|
@ -495,8 +483,8 @@ class ServiceActions
|
|||
}
|
||||
}
|
||||
|
||||
if ($bCacheEnabled) {
|
||||
$this->oActions->cacheByKey($this->sQuery . $sMinify);
|
||||
if ($sCacheFileName) {
|
||||
$this->oActions->cacheByKey(\md5($sCacheFileName . ($bJson ? 1 : 0 )));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue