diff --git a/ui.php b/ui.php index 5ab70cd..e4883a0 100644 --- a/ui.php +++ b/ui.php @@ -10334,24 +10334,34 @@ private function call(string $method, string $path, array $args = [], $data = fa namespace Tqdev\PhpCrudUi\Column { use Tqdev\PhpCrudUi\Client\CrudApi; + use Tqdev\PhpCrudApi\Cache\Cache; class SpecificationService { private $api; + private $cache; + private $ttl; - public function __construct(CrudApi $api) + public function __construct(CrudApi $api, Cache $cache, int $ttl) { $this->api = $api; + $this->cache = $cache; + $this->ttl = $ttl; $this->definition = $this->getDefinition(); $this->properties = array(); } private function getDefinition(): array { - if (!isset($_SESSION['definition'])) { - $_SESSION['definition'] = $this->api->getOpenApi()?:[]; + $data = $this->cache->get('Definition'); + if ($data) { + $result = json_decode(gzuncompress($data), true); + } else { + $result = $this->api->getOpenApi()?:[]; + $data = gzcompress(json_encode($result)); + $this->cache->set('Definition', $data, $this->ttl); } - return $_SESSION['definition']; + return $result; } private function resolve($path) @@ -11437,7 +11447,7 @@ public function __construct(Config $config) $api = new CrudApi($config->getUrl()); $prefix = sprintf('phpcrudui-%s-%s-', substr(md5($config->getUrl()), 0, 12), substr(md5(__FILE__), 0, 12)); $cache = CacheFactory::create($config->getCacheType(), $prefix, $config->getCachePath()); - $definition = new SpecificationService($api); + $definition = new SpecificationService($api, $cache, $config->getCacheTime()); $responder = new TemplateResponder($config->getTemplatePath()); $router = new SimpleRouter($config->getBasePath(), $responder, $cache, $config->getCacheTime(), $config->getDebug()); $responder->setVariable('base', $router->getBasePath());