Files
thetool/lib/mvcfronk/mfValuecache/mfValuecache.php
2025-12-16 01:47:04 +01:00

70 lines
1.5 KiB
PHP

<?php
class mfValuecache {
public static $instance;
public $cache = [];
private function __construct() { }
public static function singleton() {
if(!isset(self::$instance)) {
$c=__CLASS__;
self::$instance=new $c();
}
return self::$instance;
}
public function get($key) {
if(array_key_exists($key, $this->cache)) {
return $this->cache[$key];
}
return null;
}
public function set($key, $value) {
$this->cache[$key] = $value;
return true;
}
public function getCache() {
return $this->cache;
}
public function delete($key) {
unset($this->cache[$key]);
return true;
}
public function purge($beginning = "", $casesensitive = true) {
if(!$beginning) {
$this->cache = [];
return true;
}
foreach($this->cache as $key => $value) {
if(!$casesensitive) {
if(strpos(strtolower($key), strtolower($beginning)) === 0) {
unset($this->cache[$key]);
}
}
if(strpos($key, $beginning) === 0) {
unset($this->cache[$key]);
}
}
return true;
}
public function getMfObject($objectname, $id) {
$object = $this->get("mfObjectmodel-$objectname-".$id);
if(!$object) {
$object = new $objectname($id);
$a = new ADBNetzgebiet(1);
if((method_exists($object, "isLoaded") && !$object->isLoaded()) || !$object->id) {
$this->set("mfObjectmodel-$objectname-".$id, $object);
}
}
return $object;
}
}