N°7068 - Add emulation for apc_exists function (#460)

* Emulate missing apc_exists

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update core/apc-emulation.php

---------

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
This commit is contained in:
Thomas Casteleyn
2024-02-13 21:13:41 +01:00
committed by GitHub
parent 8275de8fa7
commit 78133418d7

View File

@@ -97,6 +97,28 @@ function apc_delete($key)
return $bRet1 || $bRet2;
}
/**
* Checks if APCu emulation key exists
* @param string|string[] $keys A string, or an array of strings, that contain keys.
* @return bool|string[] Returns TRUE if the key exists, otherwise FALSE
* Or if an array was passed to keys, then an array is returned that
* contains all existing keys, or an empty array if none exist.
*/
function apc_exists($keys)
{
if (is_array($keys)) {
$aExistingKeys = [];
foreach ($keys as $sKey) {
if (apcFile::ExistsOneFile($sKey)) {
$aExistingKeys[] = $sKey;
}
}
return $aExistingKeys;
} else {
return apcFile::ExistsOneFile($keys);
}
}
class apcFile
{
// Check only once per request
@@ -183,6 +205,15 @@ class apcFile
return true;
}
/**
* Check if cache key exists
* @param $sKey
* @return bool
*/
static public function ExistsOneFile($sKey) {
return is_file(self::GetCacheFileName('-' . $sKey)) || is_file(self::GetCacheFileName($sKey));
}
/** Get one cache entry content.
* @param $sKey
* @return bool|mixed