Exemple #1
0
 /**
  * Creates the PSR-6 cache pool based on the application.ini config
  * and sets it in the Zend_Registry
  *
  * @throws Zend_Exception
  */
 public function init()
 {
     /** @var Zend_Config $config */
     $config = Zend_Registry::get('config');
     if (!$config instanceof Zend_Config) {
         throw new Exception(Factory::EXCEPTION_CONFIG_AND_CONFIG_FILE_NOT_SET);
     }
     try {
         $config = $config->resources->CachePool;
     } catch (Exception $e) {
         throw new Exception(Factory::EXCEPTION_CONFIG_AND_CONFIG_FILE_NOT_SET);
     }
     $adapterIndex = Config::INDEX_ADAPTER;
     $defaultAdapterIndex = Config::INDEX_DEFAULT_ADAPTER;
     /** @var array $config */
     $config = $config->toArray();
     if (empty($config[$adapterIndex]) || !is_array($config[$adapterIndex])) {
         throw new Exception(Factory::EXCEPTION_BAD_CONFIG);
     }
     $defaultAdapter = !empty($config[$defaultAdapterIndex]) ? $config[$defaultAdapterIndex] : null;
     $cachePoolFactory = new Factory();
     $adaptersConfig = $config[$adapterIndex];
     foreach ($adaptersConfig as $adapterName => $config) {
         $cachePoolConfig = array(Config::INDEX_CACHE => array($adapterIndex => array($adapterName => $config)));
         $cachePoolFactory->setConfig($cachePoolConfig);
         $cachePool = $cachePoolFactory->makeTaggable($adapterName);
         Zend_Registry::set($adapterName, $cachePool);
         if ($adapterName === $defaultAdapter) {
             Zend_Registry::set($defaultAdapterIndex, $cachePool);
         }
     }
 }
 /**
  * Tests that the factory throws exception when the adapter specified by the 'type' index is not implemented.
  *
  * @param array $config Adapter configuration
  *
  * @dataProvider validConfigurationDataProvider
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage There is no cache pool factory implementation for the adapter "local"
  */
 public function testThatFactoryThrowsExceptionWhenAdapterDoesNotExist(array $config)
 {
     $config[Config::INDEX_CACHE][Config::INDEX_ADAPTER][$this->adapterName][Config::INDEX_TYPE] = 'local';
     $cachePoolFactory = new Factory();
     $cachePoolFactory->setConfig($config);
     $cachePoolFactory->make($this->adapterName);
 }
Exemple #3
0
<?php

date_default_timezone_set('Europe/Berlin');
const CACHE_KEY = 'test_key';
const CACHE_VALUE = 'test_value';
const CACHE_TTL = 2;
require_once __DIR__ . '/../../vendor/autoload.php';
use Cache\Factory\Factory;
$cachePoolFactory = new Factory();
$cachePoolFactory->setConfigFile(__DIR__ . '/../config/cache.yml');