本文整理汇总了PHP中Zend_Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Cache类的具体用法?PHP Zend_Cache怎么用?PHP Zend_Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialise
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;
}
示例2: setOptions
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);
}
示例3: getResource
public function getResource()
{
if (!$this->_resource) {
$this->_resource = Zend_Cache::factory($this->getVar('frontend', 'Core'), $this->getVar('backend', 'File'));
}
return $this->_resource;
}
示例4: getLibrary
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;
}
示例5: __construct
/**
* 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);
}
示例6: setupCache
/**
* 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);
}
示例7: testBackend
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'));
}
示例8: preDispatch
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) {
}
}
}
示例9: getCache
/**
* Получаем объект кеша (все пути и настройки тупо захордкорджены)
* @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;
}
示例10: _initSpreadsheetCaching
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);
}
示例11: __construct
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');
}
}
示例12: _initDbCache
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);
}
示例13: getLatLng
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;
}
开发者ID:MarS2806,项目名称:Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD-,代码行数:27,代码来源:Google.php
示例14: _getSSObject
/**
* 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;
}
示例15: __construct
/**
* 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']
// );
}