本文整理汇总了PHP中Zend_Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Cache类的具体用法?PHP Zend_Cache怎么用?PHP Zend_Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Cache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:luismayta,项目名称:zrt,代码行数:28,代码来源:Cache.php
示例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);
}
开发者ID:manishkhanchandani,项目名称:world_mkgxy,代码行数:7,代码来源:cache.class.php
示例3: getResource
public function getResource()
{
if (!$this->_resource) {
$this->_resource = Zend_Cache::factory($this->getVar('frontend', 'Core'), $this->getVar('backend', 'File'));
}
return $this->_resource;
}
开发者ID:hientruong90,项目名称:ee_14_installer,代码行数:7,代码来源:Cache.php
示例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;
}
开发者ID:nanpou,项目名称:concrete5,代码行数:32,代码来源:cache.php
示例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);
}
开发者ID:5haman,项目名称:knowledgetree,代码行数:12,代码来源:Apc.php
示例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);
}
开发者ID:madberry,项目名称:WhiteLabelTransfer,代码行数:14,代码来源:Cache.php
示例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'));
}
开发者ID:redema,项目名称:silverstripe-zcba,代码行数:30,代码来源:ZendCacheBackendMemoryTest.php
示例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) {
}
}
}
开发者ID:rogercastaneda,项目名称:owlsys,代码行数:33,代码来源:Locale.php
示例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;
}
开发者ID:ei-grad,项目名称:phorm,代码行数:14,代码来源:Config.php
示例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);
}
开发者ID:tests1,项目名称:zendcasts,代码行数:7,代码来源:Bootstrap.php
示例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');
}
}
开发者ID:AlexanderMazaletskiy,项目名称:gym-Tracker-App,代码行数:28,代码来源:Cache.php
示例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);
}
开发者ID:rdallasgray,项目名称:bbx,代码行数:7,代码来源:ContextDependencies.php
示例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;
}
开发者ID:sasezaki,项目名称:mirror-zf1-tests,代码行数:12,代码来源:SlideShareTest.php
示例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']
// );
}
开发者ID:ngukho,项目名称:ducbui-cms,代码行数:39,代码来源:Caching(2).php
示例16: cache
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;
}
开发者ID:hoalangoc,项目名称:ftf,代码行数:26,代码来源:License.php
示例17: _loadConfig
/**
* 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;
}
开发者ID:RemiWoler,项目名称:vulnero,代码行数:41,代码来源:Application.php
示例18: setUp
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));
}
开发者ID:lortnus,项目名称:zf1,代码行数:7,代码来源:DateObjectTest.php
示例19: save
/**
* 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;
}
开发者ID:nstapelbroek,项目名称:Glitch_Lib,代码行数:43,代码来源:Class.php
示例20: init
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');
}
开发者ID:febryantosulistyo,项目名称:ClassicSocial,代码行数:26,代码来源:ImportController.php
注:本文中的Zend_Cache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论