Zend\Cache\Pattern\OutputCache

Overview

The OutputCache pattern caches output between calls to start() and end().

Quick Start

Instantiating the output cache pattern

1
2
3
4
5
use Zend\Cache\PatternFactory;

$outputCache = PatternFactory::factory('output', array(
    'storage' => 'apc'
));

Configuration Options

Option Data Type Default Value Description
storage string array Zend\Cache\Storage\StorageInterface <none> The storage to write/read cached data

Available Methods

start(string $key)

If there is a cached item with the given key display it’s data and return true else start buffering output until end() is called or the script ends and return false.

Return type:boolean
end()

Stops buffering output, write buffered data to cache using the given key on start() and displays the buffer.

Return type:boolean
setOptions(Zend\Cache\Pattern\PatternOptions $options)

Set pattern options.

Return type:Zend\Cache\Pattern\OutputCache
getOptions()

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Examples

Caching simple view scripts

1
2
3
4
5
6
7
$outputCache = Zend\Cache\PatternFactory::factory('output', array(
    'storage' => 'apc',
));

$outputCache->start('mySimpleViewScript');
include '/path/to/view/script.phtml';
$outputCache->end();
Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Cache\Pattern\OutputCache on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.