本文整理汇总了PHP中Zend_Cache::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Cache::factory方法的具体用法?PHP Zend_Cache::factory怎么用?PHP Zend_Cache::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Cache
的用法示例。
在下文中一共展示了Zend_Cache::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initCache
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);
}
示例2: _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;
}
示例3: 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;
}
示例4: 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
示例5: 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'));
}
示例6: factory
/**
* 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;
}
示例7: 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);
}
示例8: init
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;
}
示例9: 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;
}
示例10: cache
/**
* 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;
}
示例11: _initCache
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);
}
示例12: cache
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;
}
示例13: init_plugins
/**
* 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));
}
示例14: cache_init
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];
}
示例15: 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');
}