Skip to content

Commit

Permalink
use cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Jul 23, 2019
1 parent 2a22c2e commit c409c8b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit c409c8b

Please sign in to comment.