diff --git a/src/Kdyby/Translation/CatalogueCompiler.php b/src/Kdyby/Translation/CatalogueCompiler.php index 00f7e2eb..2cb60a2e 100644 --- a/src/Kdyby/Translation/CatalogueCompiler.php +++ b/src/Kdyby/Translation/CatalogueCompiler.php @@ -24,6 +24,8 @@ class CatalogueCompiler extends Nette\Object { + const TAG_TRANSLATION = 'Kdyby\\Translation\\Translator'; + /** * @var \Nette\Caching\Cache */ @@ -39,11 +41,16 @@ class CatalogueCompiler extends Nette\Object */ private $catalogueFactory; + /** + * @var Nette\Caching\IStorage + */ + private $cacheStorage; public function __construct(Nette\Caching\IStorage $cacheStorage, FallbackResolver $fallbackResolver, CatalogueFactory $catalogueFactory) { + $this->cacheStorage = $cacheStorage; $this->cache = new Cache($cacheStorage, 'Kdyby\\Translation\\Translator'); $this->fallbackResolver = $fallbackResolver; $this->catalogueFactory = $catalogueFactory; @@ -60,10 +67,22 @@ public function enableDebugMode() } + /** + * Replaces cache storage with simple memory storage (per-request). + */ + public function disableDebugMode() + { + $this->cache = new Cache($this->cacheStorage, 'Kdyby\\Translation\\Translator'); + } + - public function invalidateCache() + public function invalidateCache($onlyTranslation = FALSE) { - $this->cache->clean(array(Cache::ALL => TRUE)); + if ($onlyTranslation) { + $this->cache->clean(array(Cache::TAGS => static::TAG_TRANSLATION)); + } else { + $this->cache->clean(array(Cache::ALL => TRUE)); + } } @@ -106,7 +125,7 @@ public function compile(Translator $translator, array &$availableCatalogues, $lo } $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); - $this->cache->save($cacheKey, $availableCatalogues[$locale]->all()); + $this->cache->save($cacheKey, $availableCatalogues[$locale]->all(), array(Cache::TAGS => array(static::TAG_TRANSLATION))); return $availableCatalogues; } @@ -115,7 +134,8 @@ public function compile(Translator $translator, array &$availableCatalogues, $lo $cached = $compiled = $this->cache->load($cacheKey); if ($compiled === NULL) { $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); - $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale)); + $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale), + array(Cache::TAGS => array(static::TAG_TRANSLATION))); $cached = $this->cache->load($cacheKey); } diff --git a/tests/php.ini-win b/tests/php.ini-win new file mode 100644 index 00000000..3b1d41f0 --- /dev/null +++ b/tests/php.ini-win @@ -0,0 +1,3 @@ +[PHP] +extension_dir = "./ext" +extension=php_pdo_sqlite.dll