43 lines
850 B
PHP
43 lines
850 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 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;
|
|
}
|
|
} |