本文整理汇总了PHP中Zend\Cache\Storage\Adapter\AbstractAdapter::getOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAdapter::getOptions方法的具体用法?PHP AbstractAdapter::getOptions怎么用?PHP AbstractAdapter::getOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Cache\Storage\Adapter\AbstractAdapter
的用法示例。
在下文中一共展示了AbstractAdapter::getOptions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setCacheItem
/**
* Save item to cache
* @param string $key
* @param mixed $value
* @param array $arr_options - Optional
* Options: ttl => Overwrite configured ttl with set value. Reverts to configured ttl once completed
*/
public function setCacheItem($key, $value, $arr_options = array())
{
//check if caching is enabled
$arr_config = $this->getServiceLocator()->get("config");
if ($arr_config["front_end_application_config"]["cache_enabled"] == FALSE) {
return FALSE;
}
//end if
//adjust key
$key = $this->setIdentifier($key);
try {
/**
* Overwrite ttl
*/
if (is_numeric($arr_options["ttl"])) {
$old_ttl = $this->storageFactory->getOptions()->getTtl();
$this->storageFactory->getOptions()->setTtl((int) $arr_options["ttl"]);
$this->storageFactory->setItem($key, $value);
//reset ttl
$this->storageFactory->getOptions()->setTtl($old_ttl);
return;
}
//end if
$this->storageFactory->setItem($key, $value);
} catch (\Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
}
//end catch
}
示例2: testGetOptions
public function testGetOptions()
{
$this->_storage = $this->getMockForAbstractAdapter();
$options = $this->_storage->getOptions();
$this->assertInstanceOf('Zend\\Cache\\Storage\\Adapter\\AdapterOptions', $options);
$this->assertInternalType('boolean', $options->getWritable());
$this->assertInternalType('boolean', $options->getReadable());
$this->assertInternalType('integer', $options->getTtl());
$this->assertInternalType('string', $options->getNamespace());
$this->assertInternalType('string', $options->getKeyPattern());
}
示例3: normalizeKey
/**
* normalizes the cache id for zend cache
*
* @param string $cacheId The cache id
*
* @return string The formated cache id
*/
protected function normalizeKey($cacheId)
{
$cacheId = parent::normalizeKey($cacheId);
if (($pattern = $this->cache->getOptions()->getKeyPattern()) && !preg_match($pattern, $cacheId)) {
$pattern = str_replace(array('^[', '*$'), array('[^', ''), $pattern);
$cacheId = preg_replace($pattern, '_', $cacheId);
}
return $cacheId;
}
示例4: onFinish
/**
* Cache Response for future requests
*
* @param MvcEvent $e
* @return \Zend\Stdlib\ResponseInterface
*/
public function onFinish(MvcEvent $e)
{
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
return;
}
if (!$request->isGet()) {
return;
}
$response = $e->getResponse();
if ($response instanceof HttpResponse && !$response->isOk()) {
return;
}
// Do not continue if weren't able to compose a key
if (empty($this->cache_key)) {
return;
}
if (!$this->cacheAdapter->hasItem($this->cache_key)) {
$resourceIdentifier = $e->getRouteMatch()->getParam('resource');
$resource = call_user_func($this->getResourceLocatorService(), $resourceIdentifier);
if (!$resource instanceof Resource || !$resource->isCacheable()) {
return;
}
// Generate Response cache headers based on Resource CacheOptions
$cacheOptions = $resource->getCacheOptions();
$cacheControl = new CacheControl();
$cacheControl->addDirective($cacheOptions->getAccess());
$cacheControl->addDirective('max-age', $cacheOptions->getMaxAge());
$cacheControl->addDirective('expires', $cacheOptions->getExpires());
$cacheControl->addDirective('must-revalidate');
$dateTime = new \DateTime();
$dateTime->modify('+ ' . $cacheOptions->getExpires() . 'seconds');
$expires = new Expires();
$expires->setDate($dateTime);
$lastModified = new LastModified();
$lastModified->setDate(new \DateTime());
// Add Headers to Response Header
$response->getHeaders()->addHeader($cacheControl);
$response->getHeaders()->addHeader($expires);
$response->getHeaders()->addHeaderLine('Pragma: ' . $cacheOptions->getAccess());
$response->getHeaders()->addHeader(Etag::fromString('Etag: ' . md5($response->getBody())));
$response->getHeaders()->addHeader($lastModified);
// Set cache adapter's TTL using Resource cache expires value
$this->cacheAdapter->getOptions()->setTtl($cacheOptions->getExpires());
$this->cacheAdapter->setItem($this->cache_key, $response);
//return $response;
}
}
示例5: setCacheAdapter
/**
* Set Cache Adapter
*
* @param \Zend\Cache\Storage\Adapter\AbstractAdapter $cacheAdapter
*/
public function setCacheAdapter($cacheAdapter)
{
$this->cacheAdapter = $cacheAdapter;
$this->cacheAdapter->getOptions()->setTtl($this->getCacheOptions()->getExpires());
}