Exemplo n.º 1
0
 /**
  * Make sure factory returns core
  *
  */
 public function testFactoryReturnsCore()
 {
     $core = Zym_Cache::factory('Core', 'file', array('caching' => false));
     $this->assertEquals('Zend_Cache_Core', get_class($core));
     $core = Zym_Cache::factory();
     $this->assertEquals('Zend_Cache_Core', get_class($core));
 }
Exemplo n.º 2
0
 /**
  * Prepend temp path to paths
  *
  * @param Zend_Config $config
  */
 protected function _prependPath(Zend_Config $config)
 {
     $app = $this->getApp();
     // File
     $fileOptions = Zym_Cache::getBackendOptions('file');
     if (isset($fileOptions['cache_dir'])) {
         $fileOptions['cache_dir'] = $app->getPath(Zym_App::PATH_DATA, $fileOptions['cache_dir']);
     }
     Zym_Cache::setBackendOptions('file', $fileOptions);
     // Sqlite
     $sqliteOptions = Zym_Cache::getBackendOptions('sqlite');
     if (isset($sqliteOptions['cache_db_complete_path'])) {
         $sqliteOptions['cache_db_complete_path'] = $app->getPath(Zym_App::PATH_TEMP, $sqliteOptions['cache_db_complete_path']);
     }
     Zym_Cache::setBackendOptions('sqlite', $sqliteOptions);
 }
Exemplo n.º 3
0
 /**
  * Setup
  *
  * @return void
  */
 public function setup(Zend_Config $config)
 {
     // Setup Cache
     if ($config->get('cache')) {
         $cache = Zym_Cache::factory('Core');
         Zend_Translate::setCache($cache);
     }
     $adapter = $config->get('adapter');
     $data = $this->_parseDataPath($config->get('data'));
     $locale = $config->get('locale');
     $options = $this->_parseOptions($config->get('options')->toArray());
     $translate = new Zend_Translate($adapter, $data, null, $options);
     // Weird Zend_Translate issues
     // We cannot set a locale in the constructor
     $translate->getAdapter()->setLocale($locale);
     if ((bool) $config->get('registry')->get('enabled')) {
         /**
          * @see Zend_Registry
          */
         require_once 'Zend/Registry.php';
         Zend_Registry::set($config->get('registry')->get('key'), $translate);
     }
 }
Exemplo n.º 4
0
 /**
  * Setup
  *
  * @return void
  */
 public function setup(Zend_Config $config)
 {
     // Setup Cache
     if ($config->get('cache')) {
         $cache = Zym_Cache::factory('Core');
         Zend_Translate::setCache($cache);
     }
     $adapter = $config->get('adapter');
     $data = $this->_parseDataPath($config->get('data'));
     $options = $this->_parseOptions($config->get('options')->toArray());
     if (!($locale = $config->get('locale'))) {
         if (Zend_Registry::isRegistered('Zend_Locale')) {
             $locale = Zend_Registry::get('Zend_Locale');
         }
     }
     $translate = new Zend_Translate($adapter, $data, $locale, $options);
     if ((bool) $config->get('registry')->get('enabled')) {
         /**
          * @see Zend_Registry
          */
         require_once 'Zend/Registry.php';
         Zend_Registry::set($config->get('registry')->get('key'), $translate);
     }
 }
Exemplo n.º 5
0
 /**
  * Set cache
  *
  * @param Zend_Config $config
  */
 protected function _setCache(Zend_Config $config)
 {
     if (!$config->get('cache')) {
         return;
     }
     /**
      * @see Zym_Cache
      */
     require_once 'Zym/Cache.php';
     $cache = Zym_Cache::factory('Core');
     call_user_func(array($this->_class, 'setCache'), $cache);
 }
Exemplo n.º 6
0
 /**
  * Set default backend
  *
  * @param string|Zend_Cache_Backend $backend
  */
 public static function setDefaultBackend($backend)
 {
     self::$_defaultBackend = $backend;
 }
Exemplo n.º 7
0
 /**
  * Set cache
  *
  * @param Zend_Config $config
  */
 protected function _setCache(Zend_Config $config)
 {
     if (!$config->get('cache')) {
         return;
     }
     $cache = Zym_Cache::factory('Core');
     call_user_func(array($this->_class, 'setCache'), $cache);
 }
Exemplo n.º 8
0
<?php
$coreCache = Zym_Cache::factory();
$server    = new Zend_XmlRpc_Server();

if (!Zym_XmlRpc_Server_Cache::get('myCacheId', $coreCache, $server)) {
    require_once 'Some/Service/Class.php';
    require_once 'Another/Service/Class.php';

    // Attach Some_Service_Class with namespace 'some'
    $server->setClass('Some_Service_Class', 'some');

    // Attach Another_Service_Class with namespace 'another'
    $server->setClass('Another_Service_Class', 'another');

    Zym_XmlRpc_Server_Cache::save('myCacheId', $coreCache, $server);
}

$response = $server->handle();
echo $response;
Exemplo n.º 9
0
 /**
  * Get cache obj
  *
  * @return Zend_Cache_Core
  */
 public function getCache()
 {
     if ($this->_cache === null) {
         /**
          * @see Zym_Cache
          */
         require_once 'Zym/Cache.php';
         $cache = Zym_Cache::factory('Core');
         $this->setCache($cache);
     }
     return $this->_cache;
 }
Exemplo n.º 10
0
 /**
  * Setup cache after resources are setup
  *
  * @internal
  * @param Zym_Message $message
  */
 public function onAfterResourceSetup(Zym_Message $message)
 {
     $sender = $message->getSender();
     if ($sender instanceof Zym_App_Resource_Cache) {
         $config = $this->getConfig('cache');
         $backend = $config->get('backend') ? $config->get('backend') : Zym_Cache::getDefaultBackend();
         $backendConfig = Zym_Cache::getBackendOptions($backend);
         $frontendConfig = Zym_Cache::getFrontendOptions('Core');
         // Save
         $filename = $this->getPath(self::PATH_DATA, 'cache');
         $cache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true, 'cache_id_prefix' => $this->getName(true) . '__' . $this->getEnvironment() . '__' . get_class($this) . '__'), array('cache_dir' => $filename, 'file_name_prefix' => get_class($this)));
         $cache->save(array($backend, $frontendConfig, $backendConfig), 'cache');
     }
 }
Exemplo n.º 11
0
<?php

// Create a Zend_Cache_Core_Function cache object
$cache = Zym_Cache::factory('Function');
// Create a Zend_Cache_Core cache object
// Specifying 'Core' is optional since its
// the default param
$cache = Zym_Cache::factory();
// Create a custom core object with custom
// backend
// In this instance, any keys here override the default
// config settings applied via Zym_Cache::setConfig();
$fOptions = array('cache_id_prefix' => 'bar_');
$bOptions = array('cache_dir' => '../cache');
$cache = Zym_Cache::factory('Core', 'File', $fOptions, $bOptions);
Exemplo n.º 12
0
<?php

$config = new Zend_Config(array('default_backend' => 'Apc', 'frontends' => array('core' => array('automatic_serialization' => true, 'cache_id_prefix' => 'MyAppPrefix_')), 'backends' => array('apc' => array(), 'file' => array('cache_dir' => '../tmp'))));
Zym_Cache::setConfig($config);