Zend\Cache\Pattern\CaptureCache

Overview

The CaptureCache pattern is useful to auto-generate static resources in base of a HTTP request. The Webserver needs to be configured to run a PHP script generating the requested resource so further requests for the same resource can be shipped without calling PHP again.

It comes with basic logic to manage generated resources.

Quick Start

Simplest usage as Apache-404 handler

1
2
# .htdocs
ErrorDocument 404 /index.php
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// index.php
use Zend\Cache\PatternFactory;
$capture = Zend\Cache\PatternFactory::factory('capture', array(
    'public_dir' => __DIR__,
));

// Start capturing all output excl. headers and write to public directory
$capture->start();

// Don't forget to change HTTP response code
header('Status: 200', true, 200);

// do stuff to dynamically generate output

Configuration Options

Option Data Type Default Value Description
public_dir string <none> Location of public directory to write output to
index_filename string “index.html” The name of the first file if only a directory was requested
file_locking boolean true Locking output files on writing
file_permission integer boolean 0600 (false on win) Set permissions of generated output files
dir_permission integer boolean 0700 (false on win) Set permissions of generated output directories
umask integer boolean false Using umask on generating output files / directories

Available Methods

start(string|null $pageId = null)

Start capturing output.

Return type:void
set(string $content, string|null $pageId = null)

Write content to page identity.

Return type:void
get(string|null $pageId = null)

Get content of an already cached page.

Return type:string|false
has(string|null $pageId = null)

Check if a page has been created.

Return type:boolean
remove(string|null $pageId = null)

Remove a page.

Return type:boolean
clearByGlob(string $pattern = '**')

Clear pages matching glob pattern.

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

Set pattern options.

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

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Examples

Scaling images in base of request

1
2
# .htdocs
ErrorDocument 404 /index.php
1
2
3
4
5
6
// index.php
$captureCache = Zend\Cache\PatternFactory::factory('capture', array(
    'public_dir' => __DIR__,
));

// TODO

Table Of Contents

Previous topic

Zend\Cache\Pattern\OutputCache

Next topic

Introduction to Zend\Captcha

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

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\CaptureCache 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.