Esempio n. 1
0
 /**
  * Retrieve Zend_Cache_Manager instance
  *
  * @return Zend_Cache_Manager
  */
 public function getCacheManager()
 {
     if (null === $this->_manager) {
         $this->_manager = new Zend_Cache_Manager();
         $options = $this->getOptions();
         if (!App_Filesystem_Folder::exists($options['page']['backend']['options']['cache_dir'])) {
             if (App_Filesystem_Folder::create($options['page']['backend']['options']['cache_dir'])) {
                 $getout = fopen($options['page']['backend']['options']['cache_dir'] . "/index.html", "w") or die("Unable to open file!");
                 fwrite($getout, "Get out\n");
                 fclose($getout);
             } else {
             }
         }
         if (!App_Filesystem_Folder::exists($options['database']['backend']['options']['cache_dir'])) {
             if (App_Filesystem_Folder::create($options['database']['backend']['options']['cache_dir'])) {
                 $getout = fopen($options['database']['backend']['options']['cache_dir'] . "/index.html", "w") or die("Unable to open file!");
                 fwrite($getout, "Get out\n");
                 fclose($getout);
             } else {
             }
         }
         foreach ($options as $key => $value) {
             if ($this->_manager->hasCacheTemplate($key)) {
                 $this->_manager->setTemplateOptions($key, $value);
             } else {
                 $this->_manager->setCacheTemplate($key, $value);
             }
         }
     }
     return $this->_manager;
 }
Esempio n. 2
0
 public function __construct()
 {
     $configFile = APPLICATION_PATH . '/configs/application.ini';
     $config = new Zend_Config_Ini($configFile, APPLICATION_ENV);
     $cacheManager = new Zend_Cache_Manager();
     $cacheManager->setCacheTemplate('file', $config->resources->cachemanager->file);
     Zend_Registry::set('cacheManager', $cacheManager);
 }
Esempio n. 3
0
 /**
  * This method will instantiate the object, configure it and return it
  *
  * @return Zend_Cache_Manager
  */
 public static function getInstance()
 {
     $manager = new Zend_Cache_Manager();
     //Add the templates to the manager
     foreach (App_DI_Container::get('ConfigObject')->cache->toArray() as $k => $v) {
         $manager->setCacheTemplate($k, $v);
     }
     return $manager;
 }
Esempio n. 4
0
 public function testGettingPageCacheAlsoCreatesTagCache()
 {
     $manager = new Zend_Cache_Manager();
     $tagCacheConfig = $manager->getCacheTemplate('tagCache');
     $tagCacheConfig['backend']['options']['cache_dir'] = $this->getTmpDir();
     $manager->setCacheTemplate('tagCache', $tagCacheConfig);
     $tagCache = $manager->getCache('page')->getBackend()->getOption('tag_cache');
     $this->assertTrue($tagCache instanceof Zend_Cache_Core);
 }
Esempio n. 5
0
 /**
  * Add a new template
  * 
  * @param string $name
  * @param array $frontendOptions 
  */
 public function setCacheTemplate($name, $frontendOptions = array())
 {
     // for now only file supported
     $backendOptions = array('name' => 'File', 'options' => array('file_name_prefix' => 'fansubcms', 'cache_dir' => CACHE_PATH));
     if (APPLICATION_ENV == 'development') {
         // @todo change backend to blackhole - needs refactoring of ACL !
         $frontendOptions['options']['lifetime'] = 10;
         // cache should only live 10 seconds
     }
     $options = array('frontend' => $frontendOptions, 'backend' => $backendOptions);
     # add a new cache template for this module
     $this->_cacheManager->setCacheTemplate($name, $options);
 }
 /**
  * Retrieve Zend_Cache_Manager instance
  *
  * @return Zend_Cache_Manager
  */
 public function getCacheManager()
 {
     if (null === $this->_manager) {
         $this->_manager = new Zend_Cache_Manager();
         $options = $this->getOptions();
         foreach ($options as $key => $value) {
             if ($this->_manager->hasCacheTemplate($key)) {
                 $this->_manager->setTemplateOptions($key, $value);
             } else {
                 $this->_manager->setCacheTemplate($key, $value);
             }
         }
     }
     return $this->_manager;
 }
Esempio n. 7
0
 /**
  * Create cache manager service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return CacheManager
  * @throws Exception\RuntimeException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['cache_manager'])) {
         throw new Exception\RuntimeException('No cache manager config found.');
     }
     $options = $config['cache_manager'];
     $manager = new CacheManager();
     foreach ($options as $key => $value) {
         if ($manager->hasCacheTemplate($key)) {
             $manager->setTemplateOptions($key, $value);
         } else {
             $manager->setCacheTemplate($key, $value);
         }
     }
     return $manager;
 }
 /**
  * Retrieve Zend_Cache_Manager instance
  *
  * @return Zend_Cache_Manager
  */
 public function getCacheManager()
 {
     if (null === $this->_manager) {
         $this->_manager = new Zend_Cache_Manager();
         $options = $this->getOptions();
         foreach ($options as $key => $value) {
             // Logger
             if (isset($value['frontend']['options']['logger'])) {
                 $logger = $value['frontend']['options']['logger'];
                 if (is_array($logger)) {
                     $value['frontend']['options']['logger'] = Zend_Log::factory($logger);
                 }
             }
             // Cache templates
             if ($this->_manager->hasCacheTemplate($key)) {
                 $this->_manager->setTemplateOptions($key, $value);
             } else {
                 $this->_manager->setCacheTemplate($key, $value);
             }
         }
     }
     return $this->_manager;
 }
Esempio n. 9
0
 /**
  * @group GH-189
  */
 public function testSetsOptionsWithCustomFrontendAndBackendNamingAndAutoload()
 {
     $manager = new Zend_Cache_Manager();
     $manager->setTemplateOptions('page', array('frontend' => array('customFrontendNaming' => true), 'backend' => array('customBackendNaming' => true), 'frontendBackendAutoload' => true));
     $config = $manager->getCacheTemplate('page');
     $this->assertTrue($config['frontend']['customFrontendNaming']);
     $this->assertTrue($config['backend']['customBackendNaming']);
     $this->assertTrue($config['frontendBackendAutoload']);
 }
Esempio n. 10
0
 /**
  * Also merges enabled flag.
  *
  * @param  array $current
  * @param  array $options
  * @return array
  */
 protected function _mergeOptions(array $current, array $options)
 {
     // Do the bulk of the merging.
     $current = parent::_mergeOptions($current, $options);
     // Test for an enabled flag.
     if (isset($options['enabled'])) {
         $current['enabled'] = $options['enabled'];
     }
     if (isset($options['frontend']['customFrontendNaming'])) {
         $current['frontend']['customFrontendNaming'] = $options['frontend']['customFrontendNaming'];
     }
     if (isset($options['backend']['customBackendNaming'])) {
         $current['backend']['customBackendNaming'] = $options['backend']['customBackendNaming'];
     }
     return $current;
 }
Esempio n. 11
0
<?php

$config = array_merge(array('cacheDir' => dirname(__FILE__) . '/_cache', 'cache' => array('core' => array('frontend' => array('name' => 'Core'), 'backend' => array('name' => 'File'))), 'cacheTemplate' => array('frontend' => array('name' => 'Core', 'options' => array('lifetime' => null, 'automatic_serialization' => true)), 'backend' => array('name' => 'File', 'options' => array())), 'errors' => array('notWriteable' => 'Le dossier n\'a pas les permissions d\'écriture')), $config);
if (!is_writeable($config['cacheDir'])) {
    throw new Exception($config['errors']['notWriteable'] . ' (' . $config['cacheDir'] . ')');
}
$manager = new Zend_Cache_Manager();
foreach ($config['cache'] as $cache => $cacheConfig) {
    $conf = array_merge($config['cacheTemplate'], $cacheConfig);
    if (!isset($cacheConfig['frontend']['options'])) {
        $conf['frontend']['options'] = $config['cacheTemplate']['frontend']['options'];
    } else {
        $conf['frontend']['options'] = array_merge($config['cacheTemplate']['frontend']['options'], $cacheConfig['frontend']['options']);
    }
    $cacheConfig = $conf;
    if (!isset($cacheConfig['backend']['options']['cache_dir']) || empty($cacheConfig['backend']['options']['cache_dir'])) {
        $path = $config['cacheDir'] . '/' . $cache;
        $cacheConfig['backend']['options']['cache_dir'] = $path;
    } else {
        $path = $cacheConfig['backend']['options']['cache_dir'];
    }
    if (!file_exists($path)) {
        mkdir($path, 0755, true);
    }
    if (!is_writeable($path)) {
        throw new Exception($config['errors']['notWriteable'] . ' (' . $path . ')');
    }
    $manager->setCacheTemplate($cache, $cacheConfig);
}
return $manager;
Esempio n. 12
0
 /**
  * Get a cache type from the cache manager
  *
  * Get a cache type via the Cache Manager instance or instantiate the object if not
  * exists. Attempts to load from bootstrap if available.
  *
  * @param string
  * @return Zend_Cache_Core
  * @throws InvalidArgumentException when incorrect type is provided
  */
 public static function getCache($type)
 {
     if (is_string($type) && !array_key_exists($type, self::$_managedCaches)) {
         $front = Zend_Controller_Front::getInstance();
         if ($front->getParam('bootstrap') && $front->getParam('bootstrap')->getResource('CacheManager')) {
             $manager = $front->getParam('bootstrap')->getResource('CacheManager');
         } else {
             $manager = new Zend_Cache_Manager();
         }
         if (!$manager->hasCache($type)) {
             throw new InvalidArgumentException('Cache of type ' . $type . ' does not exist!');
         }
         self::$_managedCaches[$type] = $manager->getCache($type);
     }
     return self::$_managedCaches[$type];
 }
Esempio n. 13
0
 /**
  * get customized cache object
  * 
  * @param string $templateName
  * @param array $customOptions
  * @return Zend_Cache_Core
  */
 public function getCustomCache($templateName, array $customOptions)
 {
     $this->_cacheManager->setTemplateOptions($templateName, $customOptions);
     return $this->_cacheManager->getCache($templateName);
 }