container = $container; $container->cache = $this; } //Return model wrapper, or create + return function &__get($name){ if (!isset($this->wrappers[$name])){ $this->wrappers[$name] = new CacheWrapper($this->container->models[$name]); } return $this->wrappers[$name]; } } class CacheWrapper{ private $_wrap_array=array(); function __construct($obj){ $this->__wrap_obj = $obj; } //req - as string. If in array - return, else create + return function &__call(string $name, array $args){ $req=$name.'('.json_encode($args).')'; if (isset($this->__wrap_array[$req])) return $this->__wrap_array[$req]; $resp = call_user_func_array(array($this->__wrap_obj, $name), $args); $this->__wrap_array[$req] = $resp; $this->__wrap_saved[$req] = date('Y-m-d H:i:s'); return $resp; } function __not_cached(){ return $this->__wrap_obj; } }