private function _initCache()
 {
     $frontendOptions = array('lifetime' => null, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->dir . '../var/cache/');
     $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set('cache', $this->_cache);
 }
 /**
  * Enter description here...
  *
  * @return Zend_Service_SlideShare
  */
 protected function _getSSObject()
 {
     $ss = new Zend_Service_SlideShare(TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY, TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET, TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME, TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD, TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID);
     $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 0, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . "/SlideShare/_files"));
     $ss->setCacheObject($cache);
     return $ss;
 }
Beispiel #3
0
 public function getLibrary()
 {
     static $cache;
     if (!isset($cache) && defined('DIR_FILES_CACHE')) {
         if (is_dir(DIR_FILES_CACHE) && is_writable(DIR_FILES_CACHE)) {
             require_once DIR_LIBRARIES_3RDPARTY_CORE . '/Zend/Cache.php';
             $frontendOptions = array('lifetime' => CACHE_LIFETIME, 'automatic_serialization' => true, 'cache_id_prefix' => CACHE_ID);
             $backendOptions = array('read_control' => false, 'cache_dir' => DIR_FILES_CACHE, 'hashed_directory_level' => 2, 'file_locking' => false);
             if (defined('CACHE_BACKEND_OPTIONS')) {
                 $opts = unserialize(CACHE_BACKEND_OPTIONS);
                 foreach ($opts as $k => $v) {
                     $backendOptions[$k] = $v;
                 }
             }
             if (defined('CACHE_FRONTEND_OPTIONS')) {
                 $opts = unserialize(CACHE_FRONTEND_OPTIONS);
                 foreach ($opts as $k => $v) {
                     $frontendOptions[$k] = $v;
                 }
             }
             if (!defined('CACHE_LIBRARY') || defined("CACHE_LIBRARY") && CACHE_LIBRARY == "default") {
                 define('CACHE_LIBRARY', 'File');
             }
             $customBackendNaming = false;
             if (CACHE_LIBRARY == 'Zend_Cache_Backend_ZendServer_Shmem') {
                 $customBackendNaming = true;
             }
             $cache = Zend_Cache::factory('Core', CACHE_LIBRARY, $frontendOptions, $backendOptions, false, $customBackendNaming);
         }
     }
     return $cache;
 }
 public function getLatLng($address)
 {
     # address identifier
     $address_identifier = 'latlng_' . str_replace(array(' '), array('_'), $address);
     $address_identifier = preg_replace('/[^a-z0-9_]+/i', '', $address);
     # registry
     $registry = Zend_Registry::getInstance();
     # caching
     $frontendOptions = array('lifetime' => 2592000, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $registry->config->application->logs->tmpDir . '/cache/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     # get data
     if (($data = $cache->load($address_identifier)) === false) {
         new Custom_Logging('Hit Google: Lat/Lng for ' . $address, Zend_Log::INFO);
         $client = new Zend_Http_Client('http://maps.google.com/maps/geo?q=' . urlencode($address), array('maxredirects' => 0, 'timeout' => 30));
         $request = $client->request();
         $response = Zend_Http_Response::fromString($request);
         $body = Zend_Json::decode($response->getBody());
         $data = array();
         $data['latitude'] = !empty($body['Placemark'][0]['Point']['coordinates'][1]) ? $body['Placemark'][0]['Point']['coordinates'][1] : null;
         $data['longitude'] = !empty($body['Placemark'][0]['Point']['coordinates'][0]) ? $body['Placemark'][0]['Point']['coordinates'][0] : null;
         $cache->save($data, $address_identifier);
     } else {
         new Custom_Logging('(local cache) Hit Google: Lat/Lng for ' . $address, Zend_Log::INFO);
     }
     return $data;
 }
 public function testBackend()
 {
     $cache = Zend_Cache::factory('Core', 'Memory', $frontendOptions = array('lifetime' => 2, 'automatic_serialization' => true), $backendOptions = array());
     $this->assertInstanceOf('Zend_Cache_Core', $cache);
     $this->assertFalse($cache->load('k0'));
     $cache->save('v0');
     $this->assertTrue($cache->test('k0') > 0);
     $this->assertEquals('v0', $cache->load('k0'));
     $cache->save('v1', 'k1', array('t1'));
     $cache->save('v2', 'k2', array('t1', 't2'));
     $cache->save('v3', 'k3', array('t1', 't2', 't3'));
     $cache->save('v4', 'k4', array('t3', 't4'));
     $cache->save('v4', 'k5', array('t2', 't5'));
     $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('t1', 't2', 't3'));
     $this->assertFalse($cache->test('k3'));
     $this->assertKeys($cache, array('k1', 'k2', 'k4', 'k5'));
     $cache->clean(Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, array('t1', 't2'));
     $this->assertFalse($cache->test('k4'));
     $this->assertKeys($cache, array('k1', 'k2', 'k5'));
     $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('t1', 't2'));
     foreach (array('k1', 'k2', 'k3') as $key) {
         $this->assertFalse($cache->test($key));
     }
     $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     $this->assertFalse($cache->test('k0'));
     $cache->save('v0', 'k0');
     sleep(2);
     $cache->clean(Zend_Cache::CLEANING_MODE_OLD);
     $this->assertFalse($cache->test('k0'));
 }
Beispiel #6
0
 /**
  * Singleton method
  * @static
  * @param string $type
  * @return Zend_Cache
  */
 public static function factory($type = 'File', $options = array())
 {
     if (!self::$cache_object) {
         $front_opt = array('automatic_serialization' => true);
         if (self::$life_time) {
             $front_opt['lifeTime'] = self::$life_time;
         }
         switch ($type) {
             case 'Memcached':
                 $mhost = $options['memcache_host'];
                 $mport = $options['memcache_port'];
                 $memcache = new Memcache();
                 if (!@$memcache->connect($mhost, $mport)) {
                     require_once 'Hush/Cache/Exception.php';
                     throw new Hush_Cache_Exception('Can not connect to memcache server');
                 }
                 $back_opt = array('servers' => array('host' => $mhost, 'port' => $mport));
                 break;
             default:
                 if (!is_dir($options['cache_dir'])) {
                     if (realpath(__DAT_DIR)) {
                         mkdir(realpath(__DAT_DIR) . '/cache', 0600);
                         $options['cache_dir'] = realpath(__DAT_DIR . '/cache');
                     } else {
                         require_once 'Hush/Cache/Exception.php';
                         throw new Hush_Cache_Exception('Can not found cache_dir file directory');
                     }
                 }
                 $back_opt = array('cache_dir' => $options['cache_dir']);
                 break;
         }
         self::$cache_object = Zend_Cache::factory('Core', $type, $front_opt, $back_opt);
     }
     return self::$cache_object;
 }
 public function setOptions($lifetime = 0)
 {
     $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => SITE_DIR . '/ADODB_cache/zend');
     // getting a Zend_Cache_Core object
     $this->cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
 }
Beispiel #8
0
 public function init()
 {
     if (null === $this->_cache) {
         $options = $this->getOptions();
         if (!isset($options[0]) && $options) {
             if (!isset($options['frontend']['adapter'])) {
                 $options['frontend']['adapter'] = 'Core';
             }
             if (!isset($options['backend']['adapter'])) {
                 $options['backend']['adapter'] = 'Memcached';
             }
             if (!isset($options['frontend']['params'])) {
                 $options['frontend']['params'] = array();
             }
             if (!isset($options['backend']['params'])) {
                 $options['backend']['params'] = array();
             }
             $this->_cache = Zend_Cache::factory($options['frontend']['adapter'], $options['backend']['adapter'], $options['frontend']['params'], $options['backend']['params']);
             if (isset($options['metadata']) && true === (bool) $options['metadata']) {
                 Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
             }
             if (isset($options['translate']) && true === (bool) $options['translate']) {
                 Zend_Translate::setCache($this->_cache);
             }
             if (isset($options['locale']) && true === (bool) $options['locale']) {
                 Zend_Locale::setCache($this->_cache);
             }
         } else {
             $this->_cache = false;
         }
         $key = isset($options['registry']) && !is_numeric($options['registry']) ? $options['registry'] : self::DEFAULT_REGISTRY_KEY;
         Zend_Registry::set($key, $this->_cache);
     }
     return $this->_cache;
 }
Beispiel #9
0
	private function cache($m_v = array())
	{
		if (Zend_Registry::isRegistered('Zend_Cache') && ($cache = Zend_Registry::get('Zend_Cache')))
		{
			$id = '_new_younetcore_data_';
			$val = (bool)$cache -> load($id);
			$frontendOptions = array(
				'automatic_serialization' => true,
				'cache_id_prefix' => 'Engine4_',
				'lifetime' => '86400',
				'caching' => true,
			);
			$backendOptions = array('cache_dir' => APPLICATION_PATH . '/temporary/cache');
			$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
			if ($data = $cache -> load($id))
			{
				return $data;
			}
			else
			{
				$cache -> save($m_v);
				return false;
			}
		}
		return false;
	}
Beispiel #10
0
 /**
  * This will obtain the cache system
  * 
  * @return Zend_Cache
  */
 private function cache()
 {
     $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/cache.xml', APPLICATION_ENV);
     //TODO this should be parsed once in the bootstrap
     $cache = Zend_Cache::factory($config->cache->frontend->name, $config->cache->backend->name, $config->cache->frontend->options->toArray(), $config->cache->backend->options->toArray());
     return $cache;
 }
Beispiel #11
0
 public function _initCache()
 {
     $frontendOptions = array('automatic_serialization' => true);
     $backendOptions = array('cache_dir' => '../cache/');
     $dbCache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($dbCache);
 }
Beispiel #12
0
 public function cache()
 {
     $frontendOptions = array("lifetime" => "43200", "automatic_serialization" => true);
     $backendOptions = array("cache_dir" => APPLICATION_PATH . "/../cache/");
     $cache = Zend_Cache::factory("Core", "File", $frontendOptions, $backendOptions);
     return $cache;
 }
/**
 * Initialize plugins hook system
 */
function init_plugins()
{
    include APPPATH . 'config/cache.php';
    $feEngine = $config['plugins_frontend_engine'];
    $feOptions = $config['plugins_frontend'];
    $beEngine = $config['plugins_backend_engine'];
    $beOptions = $config['plugins_backend'];
    if (isset($beOptions['cache_dir']) && !file_exists($beOptions['cache_dir'])) {
        mkdir($beOptions['cache_dir']);
        chmod($beOptions['cache_dir'], 0777);
    }
    $cache = Zend_Cache::factory($feEngine, $beEngine, $feOptions, $beOptions);
    $pluginsConfigArray = $cache->load('pluginsConfig');
    if (!$pluginsConfigArray) {
        $pluginsConfigArray = array();
        $pluginConfDirHandler = opendir(APPPATH . 'config/plugins');
        while (false !== ($pluginConfigFile = readdir($pluginConfDirHandler))) {
            if (preg_match('~^.*?\\.ini$~si', $pluginConfigFile)) {
                try {
                    $pluginConfig = new Zend_Config_Ini(APPPATH . 'config/plugins/' . $pluginConfigFile, 'plugins');
                    $pluginsConfigArray = array_merge_recursive($pluginsConfigArray, $pluginConfig->toArray());
                } catch (Exception $e) {
                }
            }
        }
        closedir($pluginConfDirHandler);
        $cache->save($pluginsConfigArray, 'pluginsConfig');
    }
    Zend_Registry::getInstance()->set('pluginsConfig', new Zend_Config($pluginsConfigArray));
}
Beispiel #14
0
 public static function cache_init($options = false)
 {
     $defaultCacheExpire = Config::get_mandatory("DEFAULT_CACHE_EXPIRE");
     if (empty($defaultCacheExpire)) {
         $defaultCacheExpire = 0;
     }
     $lifetime = isset($options["lifetime"]) ? $options["lifetime"] : $defaultCacheExpire;
     $cacheExists = false;
     if (!empty(self::$_caches[$lifetime])) {
         $cacheExists = true;
     }
     if (!$cacheExists && Config::get_optional("MEMCACHE_ON") == true) {
         $servers = array('host' => Config::get_mandatory("memcache_host"), 'port' => Config::get_mandatory("memcache_port"), 'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT, 'weight' => 1);
         $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true);
         $backendOptions = array('servers' => $servers);
         $memcache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
         // test memcache & clean out old entries if they exist
         if (@$memcache->save("test", "test_id")) {
             $num = mt_rand(0, 100);
             if ($num == 1) {
                 $memcache->clean(Zend_Cache::CLEANING_MODE_OLD);
                 Logger::log("cache cleaned: " . __METHOD__ . " line: " . __LINE__, Logger::DEBUG);
             }
             self::$_caches[$expire] = $memcache;
         } else {
             self::$_caches[$expire] = false;
         }
     } elseif (!$cacheExists) {
         $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true, 'cache_id_prefix' => Config::get_optional('CACHE_ID_PREFIX'));
         $backendOptions = array('cache_dir' => sprintf("%s/../%s/", DOCUMENT_ROOT, Config::get_mandatory("CACHE_DIR")));
         self::$_caches[$lifetime] = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         self::doClean($options);
     }
     return self::$_caches[$lifetime];
 }
 public function init()
 {
     // Get cache
     if (!Zend_Registry::isRegistered('Cache')) {
         throw new Engine_Exception('Caching is required, please ensure temporary/cache is writable.');
     }
     $oldCache = Zend_Registry::get('Cache');
     // Make new cache
     $this->_cache = Zend_Cache::factory('Core', $oldCache->getBackend(), array('cache_id_prefix' => 'engine4installimport', 'lifetime' => 7 * 86400, 'ignore_user_abort' => true, 'automatic_serialization' => true));
     // Get existing token
     $token = $this->_cache->load('token', true);
     // Check if already logged in
     if (!Zend_Registry::get('Zend_Auth')->getIdentity()) {
         // Check if token matches
         if (null == $this->_getParam('token')) {
             return $this->_helper->redirector->gotoRoute(array(), 'default', true);
         } else {
             if ($token !== $this->_getParam('token')) {
                 echo Zend_Json::encode(array('status' => false, 'erros' => 'Invalid token'));
                 exit;
             }
         }
     }
     // Add path to autoload
     Zend_Registry::get('Autoloader')->addResourceType('import', 'import', 'Import');
 }
Beispiel #16
0
 /**
  * setup Zend_Cache
  *
  * @link    http://framework.zend.com/manual/en/zend.cache.introduction.html
  * @param   int     $lifetime
  * @param   string  $cacheObj
  */
 public function setupCache($lifetime, $cacheObj)
 {
     $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => ROOT_DIR . '/data/cache/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set($cacheObj, $cache);
 }
Beispiel #17
0
 /**
  *    generateAction
  *    
  *    Generate RSS feeds
  *
  *   @param  type    string      (optional) Content type ('problem' / 'finfo' / 'idea' / 'all'), 'all' by default
  *   @param  count   integer     (optional) How many items to generate
  *   
  */
 public function generateAction()
 {
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Set custom RSS cache (lifetime 10 minutes)
     $cacheFrontend = array('lifetime' => 600, 'automatic_serialization' => true);
     $cacheBackend = array('cache_dir' => '../tmp/');
     $cache = Zend_Cache::factory('core', 'File', $cacheFrontend, $cacheBackend);
     // Make baseurl absolute URL
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     $this->view->absoluteBaseUrl = $absoluteBaseUrl;
     // Get parameters
     $params = $this->getRequest()->getParams();
     // Get content type
     $cty = isset($params['type']) ? $params['type'] : 'all';
     // Get number of items
     $count = isset($params['count']) ? $params['count'] : 10;
     // Set array for content data
     $data = array();
     // Get recent content by type
     $content = new Default_Model_Content();
     $data = $content->listRecent($cty, 1, $count, null, $this->view->language, null);
     // Set to view
     $this->view->cache = $cache;
     $this->view->cacheIdentifier = 'RSS_' . md5($cty . $count);
     $this->view->contentData = $data;
 }
Beispiel #18
0
 protected function _initDbCache()
 {
     $frontendOptions = array('automatic_serialization' => true);
     $backendOptions = array('cache_dir' => APPLICATION_PATH . '/../cache');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
 }
 /**
  * Fetch a set of news from local data, filtered by news categories.
  *
  * Raw item list is cached - the returned result of the filtering should
  * ideally be secondarily cached by calling code on a per-end-user basis.
  *
  * Intended to be used as part of an AJAX request for the external news
  * ticker.
  *
  * @param array $categoryIds
  *
  * @return array Array of Model_Cms_ExternalNews_Item objects.
  */
 public function fetchNews($categoryIds = array())
 {
     $params = Zend_Registry::get('params');
     // Get all news items from DB, result cached with Zend_Cache, and filter/return required categories
     // Initialise the all items cache
     $frontendOptions = array('lifetime' => $params->cms->extnews->fetchAllItemsCacheLifetime, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $params->cms->extnews->cachePath);
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     if (($externalNews = $cache->load('externalNews')) === false) {
         // Cache miss, get new results
         $this->_useItemDatasource();
         $externalNews = $this->_externalNewsItemDatasource->getAllItems();
         $cache->save($externalNews, 'externalNews');
     } else {
         // Cache hit
     }
     // Filter news items by category IDs
     $returnVal = array();
     $count = 0;
     foreach ($externalNews as $item) {
         // If item passes category filter, include it
         if (in_array($item->categoryId, $categoryIds)) {
             $returnVal[] = $item;
             $count++;
         }
         // Quit filtering once we have all x display items
         if ($count >= $params->cms->extnews->displayItemsMax) {
             break;
         }
     }
     return $returnVal;
 }
 public function __construct($useCache = null, $cacheType = null, $frontendName = 'Core')
 {
     if (!isset($useCache)) {
         $useCache = false;
     }
     if (!isset($cacheType)) {
         $cacheType = 'file';
     }
     $automaticSerialization = true;
     if ($cacheType == self::FILE) {
         $config = vkNgine_Config::getSystemConfig();
         $cacheDir = $config->cache->dir;
         if (!file_exists($cacheDir)) {
             mkdir($cacheDir);
         }
         $backendName = $cacheType;
         $backendOptions = array('cache_dir' => $cacheDir);
         $frontendOptions = array('caching' => $useCache, 'lifetime' => $config->cache->lifetime, 'automatic_serialization' => $automaticSerialization);
         $this->_cacheObject = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions);
     } elseif ($cacheType == self::MEMCACHED) {
         $backendName = $cacheType;
         $backendOptions = array('servers' => array(array('host' => '127.0.0.1', 'port' => '11211')), 'compression' => true);
         $frontendOptions = array('caching' => $useCache, 'write_control' => true, 'automatic_serialization' => $automaticSerialization, 'ignore_user_abort' => true);
         $this->_cacheObject = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions);
     } else {
         throw new Exception($cacheType . ' - cache type is not supported');
     }
 }
Beispiel #21
0
 public static function initialise(array $options = null)
 {
     self::$_cache = null;
     if (!$options) {
         $config = Zend_Registry::get('config')->cache;
         if ($config) {
             $options = $config->toArray();
         }
     }
     if (array_key_exists('frontend', $options)) {
         self::$_frontend = $options['frontend']['type'];
         if (array_key_exists('options', $options['frontend'])) {
             self::$_frontendOptions = $options['frontend']['options'];
         }
     }
     if (array_key_exists('backend', $options)) {
         self::$_backend = $options['backend']['type'];
         if (array_key_exists('options', $options['backend'])) {
             self::$_backendOptions = $options['backend']['options'];
         }
     }
     // Get the cache object.
     require_once 'Zend/Cache.php';
     // Workaround for Zend Bug ZF-10189
     require_once 'Zend/Log.php';
     self::$_cache = Zend_Cache::factory(self::$_frontend, self::$_backend, self::$_frontendOptions, self::$_backendOptions);
     self::$_enabled = true;
 }
Beispiel #22
0
 protected function _initSpreadsheetCaching()
 {
     $gdata = Zend_Registry::get('gdata');
     $spreadsheet = new ZC_SpreadsheetAdapter($gdata['user'], $gdata['password'], $gdata['spreadsheet']);
     $cache = Zend_Cache::factory('Class', "File", array('cached_entity' => $spreadsheet), array('cache_dir' => TMP_PATH));
     Zend_Registry::set('spreadsheet', $cache);
 }
Beispiel #23
0
 /**
  * Constructor: initialize cache
  * 
  * @param  array|Zend_Config $options 
  * @return void
  * @throws Exception
  */
 public function __construct()
 {
     // Khoi tao cache
     //    	$this->_cache = Zend_Registry::get('cache');
     // Cache options
     $frontendOptions = array('lifetime' => 1200, 'automatic_serialization' => true);
     $backendOptions = array('lifetime' => 3600, 'cache_dir' => BASE_PATH . '/cache/');
     // Get a Zend_Cache_Core object
     $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     //        Zend_Registry::set('cache', $cache);
     // Return it, so that it can be stored by the bootstrap
     //        return $cache;
     //        if ($options instanceof Zend_Config) {
     //            $options = $options->toArray();
     //        }
     //        if (!is_array($options)) {
     //            throw new Exception('Invalid cache options; must be array or Zend_Config object');
     //        }
     //
     //        if (array('frontend', 'backend', 'frontendOptions', 'backendOptions') != array_keys($options)) {
     //            throw new Exception('Invalid cache options provided');
     //        }
     //
     //        $options['frontendOptions']['automatic_serialization'] = true;
     //
     //        $this->cache = Zend_Cache::factory(
     //            $options['frontend'],
     //            $options['backend'],
     //            $options['frontendOptions'],
     //            $options['backendOptions']
     //        );
 }
Beispiel #24
0
 /**
  * Получаем объект кеша (все пути и настройки тупо захордкорджены)
  * @todo В последствии надо перенести на использование объекта кеша из реестра загрузки
  *
  * @param array $masterfiles
  * @return Zend_Cache
  */
 public static function getCache($masterfiles = array())
 {
     $frontendOptions = array('automatic_serialization' => true, 'master_files' => $masterfiles, 'caching' => true);
     $backendOptions = array('cache_dir' => APPLICATION_PATH . '/cache/Files/');
     $cache = Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions);
     return $cache;
 }
Beispiel #25
0
    /**
     * Creates and caches Zend_Config. This can't be done in the bootstrap
     * because the application requires a configuration in order to be
     * created.
     *
     * @param   string      Config file
     * @return  array
     */
    protected function _loadConfig($file)
    {
        $frontendOptions = array(
            'automatic_serialization'   => true,
            'master_file'               => $file,
            'cache_id_prefix'           => APPLICATION_ENV
        );

        if (extension_loaded('apc')) {
            $cache = Zend_Cache::factory('File', 'Apc', $frontendOptions);
        } else {
            $cache = Zend_Cache::factory('File', 'File', $frontendOptions, array(
                'cache_dir'     => PROJECT_BASE_PATH . '/cache',
                'file_locking'  => true
            ));
        }

        if (APPLICATION_ENV != 'production' || (!$config = $cache->load('config'))) {
            $config = parent::_loadConfig($file);

            // Initialize WordPress configuration values
            $config = $this->_initWordPress($config);

            if (APPLICATION_ENV == 'production') {
                $cache->save($config, 'config');
            }
        }

        // Save for bootstrapping
        Zend_Registry::set('config', $obj = new Zend_Config($config));

        return $config;
    }
Beispiel #26
0
 public function preDispatch($request)
 {
     try {
         $locale = new Zend_Locale();
         $locale->setDefault('en');
         $locale->setLocale(Zend_Locale::BROWSER);
         $requestedLanguage = key($locale->getBrowser());
         $formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
         $writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'translations.log');
         $writer->setFormatter($formatter);
         $logger = new Zend_Log($writer);
         $frontendOptions = array('cache_id_prefix' => 'translation', 'lifetime' => 86400, 'automatic_serialization' => true);
         $backendOptions = array('cache_dir' => APPLICATION_CACHE_PATH);
         $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         $options = array('adapter' => 'gettext', 'scan' => Zend_Translate::LOCALE_FILENAME, 'content' => APPLICATION_PATH . '/languages/en/en.mo', 'locale' => 'auto', 'disableNotices' => true);
         $translate = new Zend_Translate($options);
         if (!$translate->isAvailable($locale->getLanguage())) {
             $locale->setLocale('en');
         } else {
             $translate->setLocale($locale);
         }
         $translate->setCache($cache);
         Zend_Registry::set('locale', $locale->getLanguage());
         Zend_Registry::set('Zend_Translate', $translate);
     } catch (Exception $e) {
         try {
             $writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugin-locale.log');
             $logger = new Zend_Log($writer);
             $logger->log($e->getMessage(), Zend_Log::ERR);
         } catch (Exception $e) {
         }
     }
 }
Beispiel #27
0
 /**
  * Setup Cache
  *
  * @param array $config
  */
 public function _setupCache($config)
 {
     if (!isset($config['frontendName'])) {
         $message = 'Cache config doesn\'t contain frontendName';
         throw new Robo47_Application_Resource_Exception($message);
     }
     if (!isset($config['backendName'])) {
         $message = 'Cache config doesn\'t contain backendName';
         throw new Robo47_Application_Resource_Exception($message);
     }
     if (!isset($config['frontendOptions'])) {
         $config['frontendOptions'] = array();
     }
     if (!isset($config['backendOptions'])) {
         $config['backendOptions'] = array();
     }
     if (!isset($config['customFrontendNaming'])) {
         $config['customFrontendNaming'] = false;
     }
     if (!isset($config['customBackendNaming'])) {
         $config['customBackendNaming'] = false;
     }
     if (!isset($config['autoload'])) {
         $config['autoload'] = false;
     }
     $cache = Zend_Cache::factory($config['frontendName'], $config['backendName'], $config['frontendOptions'], $config['backendOptions'], $config['customFrontendNaming'], $config['customBackendNaming'], $config['autoload']);
     if (isset($config['registryKey'])) {
         Zend_Registry::set($config['registryKey'], $cache);
     }
     return $cache;
 }
Beispiel #28
0
 public function setUp()
 {
     date_default_timezone_set('Europe/Paris');
     require_once 'Zend/Cache.php';
     $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/../_files/'));
     Zend_Date_DateObjectTestHelper::setOptions(array('cache' => $cache));
 }
Beispiel #29
0
 public function getResource()
 {
     if (!$this->_resource) {
         $this->_resource = Zend_Cache::factory($this->getVar('frontend', 'Core'), $this->getVar('backend', 'File'));
     }
     return $this->_resource;
 }
Beispiel #30
0
 public function getLibrary()
 {
     static $cache;
     if (!isset($cache) && defined('DIR_FILES_CACHE')) {
         if (is_dir(DIR_FILES_CACHE) && is_writable(DIR_FILES_CACHE)) {
             Loader::library('3rdparty/Zend/Cache');
             $frontendOptions = array('lifetime' => CACHE_LIFETIME, 'automatic_serialization' => true, 'cache_id_prefix' => CACHE_ID);
             $backendOptions = array('cache_dir' => DIR_FILES_CACHE);
             if (defined('CACHE_BACKEND_OPTIONS')) {
                 $opts = unserialize(CACHE_BACKEND_OPTIONS);
                 foreach ($opts as $k => $v) {
                     $backendOptions[$k] = $v;
                 }
             }
             if (defined('CACHE_FRONTEND_OPTIONS')) {
                 $opts = unserialize(CACHE_FRONTEND_OPTIONS);
                 foreach ($opts as $k => $v) {
                     $frontendOptions[$k] = $v;
                 }
             }
             if (!defined('CACHE_LIBRARY') || defined("CACHE_LIBRARY") && CACHE_LIBRARY == "default") {
                 define('CACHE_LIBRARY', 'File');
             }
             $cache = Zend_Cache::factory('Core', CACHE_LIBRARY, $frontendOptions, $backendOptions);
         }
     }
     return $cache;
 }