Files
thetool/lib/mvcfronk/mfValuecache/mfValuecache.php
2024-08-20 12:51:54 +02:00

47 lines
919 B
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;
}
public function getCache() {
return $this->cache;
}
public function delete($key) {
unset($this->cache[$key]);
}
public function getMfObject($objectname, $id) {
$object = $this->get("mfObjectmodel-$objectname-".$id);
if(!$object) {
$object = new $objectname($id);
if($object->id) {
$this->set("mfObjectmodel-$objectname-".$id, $object);
}
}
return $object;
}
}