示例#1
0
文件: Minify.php 项目: ei-grad/phorm
 /**
  * Минификация яваскриптов
  * 
  * @return void
  */
 public function jsAction()
 {
     $this->_response->setHeader('Content-Type', 'text/javascript', true);
     if (isset($this->_params['files'])) {
         $files = explode(',', $this->_params['files']);
         foreach ($files as $key => $file) {
             $file = $this->_jsdir . trim($file) . '.js';
             if (file_exists($file)) {
                 $files[$key] = $file;
             }
         }
         if (!empty($files)) {
             $cacheid = 'minify_js_' . md5(implode(',', $files));
             $this->_cache->setMasterFiles($files);
             if ($this->_cache->test($cacheid)) {
                 $this->_response->setBody($this->_cache->load($cacheid));
             } else {
                 require_once 'Phorm/Plugin/jsmin.php';
                 $str = '';
                 foreach ($files as $file) {
                     $str .= file_get_contents($file) . PHP_EOL;
                 }
                 $js = JSMin::minify($str);
                 $this->_cache->save($js, $cacheid);
                 $this->_response->setBody($js);
             }
         }
     }
 }
示例#2
0
文件: Cache.php 项目: rtsantos/mais
 /**
  *
  * @param string|array $data
  * @param string $id
  * @return \ZendT_Cache 
  */
 public function set($data, $id = '')
 {
     if ($id == '') {
         $id = $this->_id;
     }
     if ($id == '') {
         throw new ZendT_Exception('Favor informar o id do cache!');
     }
     $data = serialize($data);
     $this->_cache->save($data, $id);
     return $this;
 }
示例#3
0
 /** Perform a curl request based on url provided
  * @access public
  * @param string $method
  * @param array $params
  * @return type
  */
 public function get($method, $params)
 {
     $url = $this->createUrl($method, $params);
     if (!$this->_cache->test(md5($url))) {
         $config = array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_POST => true, CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"], CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_LOW_SPEED_TIME => 1));
         $client = new Zend_Http_Client($url, $config);
         $response = $client->request();
         $data = $response->getBody();
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load(md5($url));
     }
     return Zend_Json_Decoder::decode($data, Zend_Json::TYPE_OBJECT);
 }
示例#4
0
 /** Get data from the endpoint
  * @access protected
  * @return string
  */
 protected function getData()
 {
     $key = md5($this->_uri);
     if (!$this->_cache->test($key)) {
         $graph = new EasyRdf_Graph(self::URI . $this->_uri . self::SUFFIX);
         $graph->load();
         $data = $graph->resource(self::URI . $this->_uri);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load($key);
     }
     EasyRdf_Namespace::set('dcterms', 'http://purl.org/dc/terms/');
     EasyRdf_Namespace::set('pleiades', 'http://pleiades.stoa.org/places/vocab#');
     return $data;
 }
示例#5
0
文件: Cache.php 项目: luismayta/zrt
 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;
 }
 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);
 }
示例#7
0
 public function getResource()
 {
     if (!$this->_resource) {
         $this->_resource = Zend_Cache::factory($this->getVar('frontend', 'Core'), $this->getVar('backend', 'File'));
     }
     return $this->_resource;
 }
示例#8
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;
 }
示例#9
0
 /**
  * Constructor
  * 
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('apc')) {
         Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
示例#10
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);
 }
 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'));
 }
示例#12
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) {
         }
     }
 }
示例#13
0
文件: Config.php 项目: ei-grad/phorm
 /**
  * Получаем объект кеша (все пути и настройки тупо захордкорджены)
  * @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;
 }
示例#14
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);
 }
 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');
     }
 }
示例#16
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);
 }
 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;
 }
 /**
  * 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;
 }
示例#19
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']
     //        );
 }
示例#20
0
文件: License.php 项目: hoalangoc/ftf
	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;
	}
示例#21
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;
    }
示例#22
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));
 }
示例#23
0
 /**
  * Save some data in a cache
  *
  * @param  mixed $data           Data to put in cache (can be another type than string if automatic_serialization is on)
  * @param  string $id             Cache id (if not set, the last cache id will be used)
  * @param  array $tags           Cache tags
  * @param  int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
  * @throws Zend_Cache_Exception
  * @return boolean True if no problem
  */
 public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
 {
     if (!$this->_options['caching']) {
         return true;
     }
     if ($id === null) {
         $id = $this->_lastId;
     } else {
         $id = $this->_id($id);
     }
     self::_validateIdOrTag($id);
     if (is_resource($data)) {
         Zend_Cache::throwException('Data can\'t be a resource as it can\'t be serialized');
     }
     /*if ($this->_options['ignore_user_abort'])
       {
           $abort = ignore_user_abort(true);
       }*/
     $result = $this->_backend->save($data, $id, $tags, $specificLifetime);
     /*if ($this->_options['ignore_user_abort'])
       {
           ignore_user_abort($abort);
       }*/
     if (!$result) {
         // maybe the cache is corrupted, so we remove it !
         if ($this->_options['logging']) {
             $this->_log(__CLASS__ . '::' . __METHOD__ . '() : impossible to save cache (id=' . $id . ')');
         }
         $this->remove($id);
         return false;
     }
     return true;
 }
 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');
 }
示例#25
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;
 }
示例#26
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;
 }
示例#27
0
 /**
  * Constructor
  * 
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     if (isset($options['servers'])) {
         $value = $options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     $this->_memcache = new Memcache();
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT;
         }
         if (!array_key_exists('port', $server)) {
             $server['port'] = Zend_Cache_Backend_Memcached::DEFAULT_PORT;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
     }
 }
示例#28
0
文件: Cache.php 项目: LWFeng/hush
 /**
  * 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;
 }
示例#29
0
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws Zend_Cache_Exception
  */
 public function __construct(array $options = array())
 {
     if (!function_exists('zend_shm_cache_store')) {
         Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
     }
     parent::__construct($options);
 }
示例#30
0
 /**
  * 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;
 }