本文整理汇总了PHP中Zend\Cache\Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->originalTimezone = date_default_timezone_get();
date_default_timezone_set('Europe/Paris');
$this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/../_files/'));
DateObjectTestHelper::setOptions(array('cache' => $this->_cache));
}
示例2: __construct
/**
* Constructor
*
* @param array $options associative array of options
* @throws \Zend\Cache\Exception
*/
public function __construct(array $options = array())
{
if (!function_exists('zend_disk_cache_store')) {
Cache\Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
}
parent::__construct($options);
}
示例3: setUp
public function setUp($notag = false)
{
$this->mkdir();
$this->_cache_dir = $this->mkdir();
@mkdir($this->_cache_dir.'/tags');
$this->_innerCache = Cache\Cache::factory('Core','File',
array('automatic_serialization'=>true), array('cache_dir'=>$this->_cache_dir.'/tags')
);
$this->_instance = new Cache\Backend\StaticBackend(array(
'public_dir' => $this->_cache_dir,
'tag_cache' => $this->_innerCache
));
$logger = new \Zend\Log\Logger(new \Zend\Log\Writer\Null());
$this->_instance->setDirectives(array('logger' => $logger));
$this->_requestUriOld =
isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
$_SERVER['REQUEST_URI'] = '/foo';
$this->_instance->setDirectives(array('logging' => true));
$this->_instance->save('bar : data to cache', bin2hex('/bar'), array('tag3', 'tag4'));
$this->_instance->save('bar2 : data to cache', bin2hex('/bar2'), array('tag3', 'tag1'));
$this->_instance->save('bar3 : data to cache', bin2hex('/bar3'), array('tag2', 'tag3'));
}
示例4: setUp
public function setUp()
{
$this->_cache = Cache::factory('Core', 'File',
array('lifetime' => 1, 'automatic_serialization' => true),
array('cache_dir' => __DIR__ . '/../../_files/'));
Cldr::setCache($this->_cache);
}
示例5: setUp
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
$this->clearRegistry();
$this->_cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => sys_get_temp_dir()));
Currency\Currency::setCache($this->_cache);
$this->helper = new Helper\Currency('de_AT');
}
示例6: _getSSObject
/**
* Enter description here...
*
* @return \Zend\Service\SlideShare
*/
protected function _getSSObject()
{
$ss = new SlideShareService(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 = Cache::factory('Core', 'File', array('lifetime' => 0, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . "/_files"));
$ss->setCacheObject($cache);
return $ss;
}
示例7: testSetDefaultMetadataCache
/**
* @group ZF-10033
*/
public function testSetDefaultMetadataCache()
{
$cache = \Zend\Cache\Cache::factory('Core', 'BlackHole', array('lifetime' => 120, 'automatic_serialization' => true));
$config = array('adapter' => 'Pdo\\Sqlite', 'params' => array('dbname' => ':memory:'), 'defaultMetadataCache' => $cache);
$resource = new DbResource($config);
$resource->init();
$this->assertInstanceOf('Zend\\Cache\\Frontend', \Zend\Db\Table\AbstractTable::getDefaultMetadataCache());
}
示例8: setUp
public function setUp()
{
$this->_cache_dir = $this->mkdir();
$this->_cache = Cache\Cache::factory(
'Core', 'File',
array('automatic_serialization'=>true),
array('cache_dir'=>$this->_cache_dir)
);
}
示例9: setUp
public function setUp()
{
$this->_locale = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'de');
$this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/'));
LocaleTestHelper::resetObject();
LocaleTestHelper::setCache($this->_cache);
putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2");
}
示例10: setUp
public function setUp()
{
$this->_locale = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'de');
$this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/'));
LocaleTestHelper::resetObject();
LocaleTestHelper::setCache($this->_cache);
// compatibilityMode is true until 1.8 therefor we have to change it
LocaleTestHelper::$compatibilityMode = false;
putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2");
}
示例11: _flush
/**
* callback for output buffering
* (shouldn't really be called manually)
*
* @param string $data Buffered output
* @return string Data to send to browser
*/
public function _flush($data)
{
$id = array_pop($this->_idStack);
if (is_null($id)) {
Cache::throwException('use of _flush() without a start()');
}
if ($this->_extension) {
$this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
} else {
$this->save($data, $id, $this->_tags);
}
return $data;
}
示例12: end
/**
* Stop the cache
*
* @param array $tags Tags array
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @param string $forcedDatas If not null, force written datas with this
* @param boolean $echoData If set to true, datas are sent to the browser
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
* @return void
*/
public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
{
if ($forcedDatas === null) {
$data = ob_get_contents();
ob_end_clean();
} else {
$data =& $forcedDatas;
}
$id = array_pop($this->_idStack);
if ($id === null) {
Cache::throwException('use of end() without a start()');
}
$this->save($data, $id, $tags, $specificLifetime, $priority);
if ($echoData) {
echo $data;
}
}
示例13: _log
/**
* Log a message at the WARN (4) priority.
*
* @param string $message
* @throws \Zend\Cache\Exception
* @return void
*/
protected function _log($message, $priority = 4)
{
if (!$this->_options['logging']) {
return;
}
if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof Log\Logger)) {
Cache::throwException('Logging is enabled but logger is not set');
}
$logger = $this->_options['logger'];
$logger->log($message, $priority);
}
示例14: makeId
/**
* Make a cache id from the function name and parameters
*
* @param callback $callback A valid callback
* @param array $args Function parameters
* @throws \Zend\Cache\Exception
* @return string Cache id
*/
public function makeId($callback, array $args = array())
{
if (!is_callable($callback, true, $name)) {
Cache::throwException('Invalid callback');
}
// functions, methods and classnames are case-insensitive
$name = strtolower($name);
// generate a unique id for object callbacks
if (is_object($callback)) {
// Closures & __invoke
$object = $callback;
} elseif (isset($callback[0])) {
// array($object, 'method')
$object = $callback[0];
}
if (isset($object)) {
try {
$tmp = @serialize($callback);
} catch (\Exception $e) {
Cache::throwException($e->getMessage());
}
if (!$tmp) {
$lastErr = error_get_last();
Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
}
$name .= '__' . $tmp;
}
// generate a unique id for arguments
$argsStr = '';
if ($args) {
try {
$argsStr = @serialize(array_values($args));
} catch (\Exception $e) {
Cache::throwException($e->getMessage());
}
if (!$argsStr) {
$lastErr = error_get_last();
throw Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
}
}
return md5($name . $argsStr);
}
示例15: getCacheObject
/**
* Gets the Zend\Cache object which will be used to cache API queries. If no cache object
* was previously set the the default will be used (Filesystem caching in /tmp with a life
* time of 43200 seconds)
*
* @return Zend\Cache\Frontend\Core The object used in caching
*/
public function getCacheObject()
{
if(!($this->_cacheobject instanceof Frontend\Core)) {
$cache = \Zend\Cache\Cache::factory('Core', 'File', array('lifetime' => 43200,
'automatic_serialization' => true),
array('cache_dir' => '/tmp'));
$this->setCacheObject($cache);
}
return $this->_cacheobject;
}