3 The `CaptureCache` pattern is useful for generating static resources to return
4 via HTTP request. When used in such a fashion, the web server needs to be
5 configured to run a PHP script generating the requested resource so that
6 subsequent requests for the same resource can be shipped without calling PHP
9 This pattern comes with basic logic for managing generated resources.
13 For use with an Apache 404 handler:
17 ErrorDocument 404 /index.php
22 use Zend\Cache\PatternFactory;
23 $capture = Zend\Cache\PatternFactory::factory('capture', [
24 'public_dir' => __DIR__,
27 // Start capturing all output, excluding headers, and write to the public
31 // Don't forget to change the HTTP response code
32 header('Status: 200', true, 200);
34 // do stuff to dynamically generate output
37 ## Configuration Options
39 Option | Data Type | Default Value | Description
40 ------ | --------- | ------------- | -----------
41 `public_dir` | `string` | none | Location of the public web root directory in which to write output.
42 `index_filename` | `string` | "index.html" | The name of the index file if only a directory was requested.
43 `file_locking` | `bool` | `true` | Whether or not to lock output files when writing.
44 `file_permission` | `int | bool` | `0600` (`false` on Windows) | Default permissions for generated output files.
45 `dir_permission` | `int | bool` | `0700` (`false` on Windows) | Default permissions for generated output directories.
46 `umask` | `int` | `bool` | `false` | Whether or not to umask generated output files / directories.
50 In addition to the methods exposed in `PatternInterface`, this implementation
51 exposes the following methods.
54 namespace Zend\Cache\Pattern;
56 use Zend\Cache\Exception;
57 use Zend\Stdlib\ErrorHandler;
59 class CaptureCache extends AbstractPattern
64 * @param string $pageId Page identifier
67 public function start($pageId = null);
70 * Write a page to the requested path.
72 * @param string $content
73 * @param null|string $pageId
74 * @throws Exception\LogicException
76 public function set($content, $pageId = null);
79 * Retrieve a generated page from the cache.
81 * @param null|string $pageId
83 * @throws Exception\LogicException
84 * @throws Exception\RuntimeException
86 public function get($pageId = null);
89 * Check if a cache exists for the given page.
91 * @param null|string $pageId
92 * @throws Exception\LogicException
95 public function has($pageId = null);
98 * Remove a page from the cache.
100 * @param null|string $pageId
101 * @throws Exception\LogicException
102 * @throws Exception\RuntimeException
105 public function remove($pageId = null);
108 * Clear cached pages that match the specified glob pattern.
110 * @param string $pattern
111 * @throws Exception\LogicException
113 public function clearByGlob($pattern = '**');
116 * Returns the generated file name.
118 * @param null|string $pageId
121 public function getFilename($pageId = null);
127 ### Scaling images in the web root
129 Using the following Apache 404 configuration:
133 ErrorDocument 404 /index.php
136 Use the following script:
140 $captureCache = Zend\Cache\PatternFactory::factory('capture', [
141 'public_dir' => __DIR__,