Skip to content

Commit

Permalink
Remove unnecessary Cache system
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorejb committed Dec 11, 2024
1 parent f7d173d commit 116a88a
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 350 deletions.
49 changes: 0 additions & 49 deletions src/Handlebars/Cache.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/Handlebars/Cache/APC.php

This file was deleted.

115 changes: 0 additions & 115 deletions src/Handlebars/Cache/Disk.php

This file was deleted.

62 changes: 0 additions & 62 deletions src/Handlebars/Cache/Dummy.php

This file was deleted.

37 changes: 2 additions & 35 deletions src/Handlebars/Handlebars.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace Handlebars;

use Handlebars\Loader\StringLoader;
use Handlebars\Cache\Dummy;
use InvalidArgumentException;

class Handlebars
Expand Down Expand Up @@ -51,8 +50,6 @@ public static function factory(array $options = []): Handlebars

private Loader $partialsLoader;

private Cache $cache;

/**
* @var callable escape function to use
*/
Expand All @@ -78,7 +75,6 @@ public static function factory(array $options = []): Handlebars
* escapeArgs => array to pass as extra parameter to escape function
* loader => Loader object
* partials_loader => Loader object
* cache => Cache object
* enableDataVariables => boolean. Enables @data variables (default: false)
*
* @param array $options array of options to set
Expand All @@ -99,10 +95,6 @@ public function __construct(Array $options = [])
$this->setPartialsLoader($options['partials_loader']);
}

if (isset($options['cache'])) {
$this->setCache($options['cache']);
}

if (isset($options['escape'])) {
if (!is_callable($options['escape'])) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -246,25 +238,6 @@ public function getPartialsLoader(): Loader
return $this->partialsLoader;
}

/**
* Set cache for current engine
*/
public function setCache(Cache $cache): void
{
$this->cache = $cache;
}

/**
* Get cache
*/
public function getCache(): Cache
{
if (!isset($this->cache)) {
$this->cache = new Dummy();
}
return $this->cache;
}

/**
* Get current escape function
*/
Expand Down Expand Up @@ -413,13 +386,7 @@ public function loadString(string $source): Template
*/
private function tokenize(string $source): array
{
$hash = md5(sprintf('version: %s, data : %s', self::VERSION, $source));
$tree = $this->getCache()->get($hash);
if ($tree === false) {
$tokens = $this->getTokenizer()->scan($source);
$tree = $this->getParser()->parse($tokens);
$this->getCache()->set($hash, $tree);
}
return $tree;
$tokens = $this->getTokenizer()->scan($source);
return $this->getParser()->parse($tokens);
}
}
Loading

0 comments on commit 116a88a

Please sign in to comment.