This commit is contained in:
2025-10-04 11:46:59 +07:00
commit 97427d7cff
498 changed files with 47596 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
// 04-Mar-2023 simple array-cache for class
namespace Hura8\Traits;
trait ClassCacheTrait
{
protected static $_cache = [];
protected static function clearCache() {
self::$_cache = [];
}
protected static function deleteCacheKey($key) {
if (array_key_exists($key, self::$_cache)) {
unset(self::$_cache[$key]);
}
}
protected static function getCache($key, callable $fn_create_value) {
if (!array_key_exists($key, self::$_cache)) {
//echo 'cached --- ';
$value = call_user_func($fn_create_value);
self::$_cache[$key] = $value;
}
// echo "from-cached-".$key."<br>";
return self::$_cache[$key];
}
}