Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved docs of cache patterns

  • Loading branch information...
commit 059988869f5159d0aa4d188ba291efbec0bbfbea 1 parent 35f2c76
Marc Bennewitz marc-mabe authored
10 docs/languages/en/index.rst
View
@@ -37,6 +37,11 @@
modules/zend.cache.storage.plugin
modules/zend.cache.backend
modules/zend.cache.pattern
+ modules/zend.cache.pattern.callback-cache
+ modules/zend.cache.pattern.class-cache
+ modules/zend.cache.pattern.object-cache
+ modules/zend.cache.pattern.output-cache
+ modules/zend.cache.pattern.capture-cache
modules/zend.captcha.intro
modules/zend.captcha.operation
modules/zend.captcha.adapters
@@ -245,6 +250,11 @@ Zend\\Cache
* :doc:`modules/zend.cache.storage.capabilities`
* :doc:`modules/zend.cache.storage.plugin`
* :doc:`modules/zend.cache.pattern`
+ * :doc:`modules/zend.cache.pattern.callback-cache`
+ * :doc:`modules/zend.cache.pattern.class-cache`
+ * :doc:`modules/zend.cache.pattern.object-cache`
+ * :doc:`modules/zend.cache.pattern.output-cache`
+ * :doc:`modules/zend.cache.pattern.capture-cache`
.. _zend.captcha:
117 docs/languages/en/modules/zend.cache.pattern.callback-cache.rst
View
@@ -0,0 +1,117 @@
+.. _zend.cache.pattern.callback-cache:
+
+Zend\\Cache\\Pattern\\CallbackCache
+===================================
+
+.. _zend.cache.pattern.callback-cache.overview:
+
+Overview
+--------
+
+The callback cache pattern caches calls of non specific functions and methods given as a callback.
+
+.. _zend.cache.pattern.callback-cache.quick-start:
+
+Quick Start
+-----------
+
+For instantiation you can use the ``PatternFactory`` or do it manual:
+
+.. code-block:: php
+ :linenos:
+
+ use Zend\Cache\PatternFactory;
+ use Zend\Cache\Pattern\PatternOptions;
+
+ // Via the factory:
+ $callbackCache = PatternFactory::factory('callback', array(
+ 'storage' => 'apc',
+ 'cache_output' => true,
+ ));
+
+ // OR, the equivalent manual instantiation:
+ $callbackCache = new \Zend\Cache\Pattern\CallbackCache();
+ $callbackCache->setOptions(new PatternOptions(array(
+ 'storage' => 'apc',
+ 'cache_output' => true,
+ )));
+
+.. _zend.cache.pattern.callback-cache.options:
+
+Configuration options
+---------------------
+
++-------------+-------------------------------------------------------------+--------------+--------------------------------------+
+|Option |Data Type |Default Value |Description |
++=============+=============================================================+==============+======================================+
+|storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
++-------------+-------------------------------------------------------------+--------------+--------------------------------------+
+|cache_output |``boolean`` |``true`` |Cache output of callback |
++-------------+-------------------------------------------------------------+--------------+--------------------------------------+
+
+.. _zend.cache.pattern.callback-cache.methods:
+
+Available Methods
+-----------------
+
+.. _zend.cache.pattern.callback-cache.methods.call:
+
+**call**
+ ``call(callable $callback, array $args = array())``
+
+ Call the specified callback or get the result from cache
+
+ Returns the result
+
+.. _zend.cache.pattern.callback-cache.methods.__call:
+
+**__call**
+ ``__call(string $function, array $args)``
+
+ Function call handler
+
+ Returns the result
+
+**generateKey**
+ ``generateKey(callable $callback, array $args = array())``
+
+ Generate a unique key in base of a key representing the callback part
+ and a key representing the arguments part.
+
+ Returns the key
+
+.. _zend.cache.pattern.callback-cache.methods.set-options:
+
+**setOptions**
+ ``setOptions(Zend\Cache\Pattern\PatternOptions $options)``
+
+ Set pattern options
+
+ Returns Zend\\Cache\\Pattern\\CallbackCache
+
+.. _zend.cache.pattern.callback-cache.methods.get-options:
+
+**getOptions**
+ ``getOptions()``
+
+ Get all pattern options
+
+ Returns ``PatternOptions`` instance.
+
+.. _zend.cache.pattern.pattern-factory.examples:
+
+Examples
+--------
+
+.. _zend.cache.pattern.callback-cache.examples.instantiate:
+
+.. rubric:: Instantiating the callback cache pattern
+
+.. code-block:: php
+ :linenos:
+
+ use Zend\Cache\PatternFactory;
+
+ $callbackCache = PatternFactory::factory('callback', array(
+ 'storage' => 'apc'
+ ));
159 docs/languages/en/modules/zend.cache.pattern.capture-cache.rst
View
@@ -0,0 +1,159 @@
+.. _zend.cache.pattern.capture-cache:
+
+Zend\\Cache\\Pattern\\CaptureCache
+=================================
+
+.. _zend.cache.pattern.capture-cache.overview:
+
+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 firther
+requests for the same resource can be shipped without calling PHP again.
+
+It comes with basic logic to manage generated resources.
+
+.. _zend.cache.pattern.capture-cache.quick-start:
+
+Quick Start
+-----------
+
+Simplest usage as Apache-404 handler
+
+.. code-block:: apacheconf
+ :linenos:
+
+ # .htdocs
+ ErrorDocument 404 /index.php
+
+.. code-block:: php
+ :linenos:
+
+ // 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
+
+.. _zend.cache.pattern.capture-cache.options:
+
+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 generationg output files / directories |
++------------------+------------------------+------------------------+-----------------------------------------------------------------+
+
+.. _zend.cache.pattern.capture-cache.methods:
+
+Available Methods
+-----------------
+
+.. _zend.cache.pattern.capture-cache.methods.start:
+
+**start**
+ ``start(string|null $pageId = null)``
+
+ Start capturing output
+
+ Returns void
+
+.. _zend.cache.pattern.capture-cache.methods.set:
+
+**set**
+ ``set(string $content, string|null $pageId = null)``
+
+ Write content to page identity
+
+ Returns void
+
+**get**
+ ``get(string|null $pageId = null)``
+
+ Get content of an already cached page
+
+ Returns string|false
+
+**has**
+ ``has(string|null $pageId = null)``
+
+ Check if a page has been created
+
+ Returns boolean
+
+**remove**
+ ``remove(string|null $pageId = null)``
+
+ Remove a page
+
+ Returns boolean
+
+**clearByGlob**
+ ``clearByGlob(string $pattern = '**')``
+
+ Clear pages matching glob pattern
+
+ Returns void
+
+.. _zend.cache.pattern.capture-cache.methods.set-options:
+
+**setOptions**
+ ``setOptions(Zend\Cache\Pattern\PatternOptions $options)``
+
+ Set pattern options
+
+ Returns Zend\\Cache\\Pattern\\OutputCache
+
+.. _zend.cache.pattern.capture-cache.methods.get-options:
+
+**getOptions**
+ ``getOptions()``
+
+ Get all pattern options
+
+ Returns ``PatternOptions`` instance.
+
+.. _zend.cache.pattern.pattern-factory.examples:
+
+Examples
+--------
+
+.. _zend.cache.pattern.capture-cache.examples.scaling-images:
+
+.. rubric:: Scaling images in base of request
+
+.. code-block:: apacheconf
+ :linenos:
+
+ # .htdocs
+ ErrorDocument 404 /index.php
+
+.. code-block:: php
+ :linenos:
+
+ // index.php
+ $captureCache = Zend\Cache\PatternFactory::factory('capture', array(
+ 'public_dir' => __DIR__,
+ ));
+
+ // TODO
149 docs/languages/en/modules/zend.cache.pattern.class-cache.rst
View
@@ -0,0 +1,149 @@
+.. _zend.cache.pattern.class-cache:
+
+Zend\\Cache\\Pattern\\ClassCache
+================================
+
+.. _zend.cache.pattern.class-cache.overview:
+
+Overview
+--------
+
+The ``ClassCache`` pattern is an extension to the ``CallbackCache`` pattern.
+It has the same methods but instead it generates the internally used callback in base of
+the configured class name and the given method name.
+
+.. _zend.cache.pattern.class-cache.quick-start:
+
+Quick Start
+-----------
+
+Instantiating the class cache pattern
+
+.. code-block:: php
+ :linenos:
+
+ use Zend\Cache\PatternFactory;
+
+ $classCache = PatternFactory::factory('class', array(
+ 'class' => 'MyClass',
+ 'storage' => 'apc'
+ ));
+
+.. _zend.cache.pattern.class-cache.options:
+
+Configuration options
+---------------------
+
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|Option |Data Type |Default Value |Description |
++========================+=============================================================+==============+=================================================================+
+|storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|class |``string`` |<none> |The class name |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|cache_output |``boolean`` |``true`` |Cache output of callback |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|cache_by_default |``boolean`` |``true`` |Cache method calls by default |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|class_cache_methods |``array`` |``[]`` |List of methods to cache (If ``cache_by_default`` is disabled) |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+|class_non_cache_methods |``array`` |``[]`` |List of methods to no-cache (If ``cache_by_default`` is enabled) |
++------------------------+-------------------------------------------------------------+--------------+-----------------------------------------------------------------+
+
+.. _zend.cache.pattern.class-cache.methods:
+
+Available Methods
+-----------------
+
+.. _zend.cache.pattern.class-cache.methods.call:
+
+**call**
+ ``call(string $method, array $args = array())``
+
+ Call the specified method of the configured class
+
+ Returns the result
+
+.. _zend.cache.pattern.class-cache.methods.__call:
+
+**__call**
+ ``__call(string $method, array $args)``
+
+ Call the specified method of the configured class
+
+ Returns the result
+
+**__set**
+
+ ``__set(string $name, mixed $value)``
+
+ Set a static property of the configured class
+
+**__get**
+
+ ``__get(string $name)``
+
+ Get a static property of the configured class
+
+**__isset**
+
+ ``__isset(string $name)``
+
+ Checks if a static property of the configured class exists
+
+**__unset**
+
+ ``__unset(string $name)``
+
+ Unset a static property of the configured class
+
+**generateKey**
+ ``generateKey(string $method, array $args = array())``
+
+ Generate a unique key in base of a key representing the callback part
+ and a key representing the arguments part.
+
+ Returns the key
+
+.. _zend.cache.pattern.class-cache.methods.set-options:
+
+**setOptions**
+ ``setOptions(Zend\Cache\Pattern\PatternOptions $options)``
+
+ Set pattern options
+
+ Returns Zend\\Cache\\Pattern\\ClassCache
+
+.. _zend.cache.pattern.class-cache.methods.get-options:
+
+**getOptions**
+ ``getOptions()``
+
+ Get all pattern options
+
+ Returns ``PatternOptions`` instance.
+
+.. _zend.cache.pattern.pattern-factory.examples:
+
+Examples
+--------
+
+.. _zend.cache.pattern.class-cache.examples.cached-feed-reader:
+
+.. rubric:: Caching of import feeds
+
+.. code-block:: php
+ :linenos:
+
+ $cachedFeedReader = Zend\Cache\PatternFactory::factory('class', array(
+ 'class' => 'Zend\Feed\Reader\Reader',
+ 'storage' => 'apc',
+
+ // The feed reader doesn't output anything
+ // so the output don't need to be catched and cached
+ 'cache_output' => false,
+ ));
+
+ $feed = $cachedFeedReader->call("import", array('http://www.planet-php.net/rdf/'));
+ // OR
+ $feed = $cachedFeedReader->import('http://www.planet-php.net/rdf/');
156 docs/languages/en/modules/zend.cache.pattern.object-cache.rst
View
@@ -0,0 +1,156 @@
+.. _zend.cache.pattern.object-cache:
+
+Zend\\Cache\\Pattern\\ObjectCache
+=================================
+
+.. _zend.cache.pattern.object-cache.overview:
+
+Overview
+--------
+
+The ``ObjectCache`` pattern is an extension to the ``CallbackCache`` pattern.
+It has the same methods but instead it generates the internally used callback in base of
+the configured object and the given method name.
+
+.. _zend.cache.pattern.object-cache.quick-start:
+
+Quick Start
+-----------
+
+Instantiating the object cache pattern
+
+.. code-block:: php
+ :linenos:
+
+ use Zend\Cache\PatternFactory;
+
+ $object = new stdClass();
+ $objectCache = PatternFactory::factory('object', array(
+ 'object' => $object,
+ 'storage' => 'apc'
+ ));
+
+.. _zend.cache.pattern.object-cache.options:
+
+Configuration options
+---------------------
+
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|Option |Data Type |Default Value |Description |
++==============================+=============================================================+=======================+=================================================================+
+|storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|object |``object`` |<none> |The object to cache methods calls of |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|object_key |``null`` ``string`` |<Class name of object> |A hopefully unique key of the object |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|cache_output |``boolean`` |``true`` |Cache output of callback |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|cache_by_default |``boolean`` |``true`` |Cache method calls by default |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|object_cache_methods |``array`` |``[]`` |List of methods to cache (If ``cache_by_default`` is disabled) |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|object_non_cache_methods |``array`` |``[]`` |List of methods to no-cache (If ``cache_by_default`` is enabled) |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+|object_cache_magic_properties |``boolean`` |``false`` |Cache calls of magic object properties |
++------------------------------+-------------------------------------------------------------+-----------------------+-----------------------------------------------------------------+
+
+.. _zend.cache.pattern.object-cache.methods:
+
+Available Methods
+-----------------
+
+.. _zend.cache.pattern.object-cache.methods.call:
+
+**call**
+ ``call(string $method, array $args = array())``
+
+ Call the specified method of the configured object
+
+ Returns the result
+
+.. _zend.cache.pattern.object-cache.methods.__call:
+
+**__call**
+ ``__call(string $method, array $args)``
+
+ Call the specified method of the configured object
+
+ Returns the result
+
+**__set**
+
+ ``__set(string $name, mixed $value)``
+
+ Set a property of the configured object
+
+**__get**
+
+ ``__get(string $name)``
+
+ Get a property of the configured object
+
+**__isset**
+
+ ``__isset(string $name)``
+
+ Checks if static property of the configured object exists
+
+**__unset**
+
+ ``__unset(string $name)``
+
+ Unset a property of the configured object
+
+**generateKey**
+ ``generateKey(string $method, array $args = array())``
+
+ Generate a unique key in base of a key representing the callback part
+ and a key representing the arguments part.
+
+ Returns the key
+
+.. _zend.cache.pattern.object-cache.methods.set-options:
+
+**setOptions**
+ ``setOptions(Zend\Cache\Pattern\PatternOptions $options)``
+
+ Set pattern options
+
+ Returns Zend\\Cache\\Pattern\\ObjectCache
+
+.. _zend.cache.pattern.object-cache.methods.get-options:
+
+**getOptions**
+ ``getOptions()``
+
+ Get all pattern options
+
+ Returns ``PatternOptions`` instance.
+
+.. _zend.cache.pattern.pattern-factory.examples:
+
+Examples
+--------
+
+.. _zend.cache.pattern.object-cache.examples.cached-filter:
+
+.. rubric:: Caching a filter
+
+.. code-block:: php
+ :linenos:
+
+ $filter = new Zend\Filter\RealPath();
+ $cachedFilter = Zend\Cache\PatternFactory::factory('object', array(
+ 'object' => $filter,
+ 'object_key' => 'RealpathFilter',
+ 'storage' => 'apc',
+
+ // The realpath filter doesn't output anything
+ // so the output don't need to be catched and cached
+ 'cache_output' => false,
+ ));
+
+ $path = $cachedFilter->call("filter", array('/www/var/path/../../mypath'));
+ // OR
+ $path = $cachedFilter->filter('/www/var/path/../../mypath');
101 docs/languages/en/modules/zend.cache.pattern.output-cache.rst
View
@@ -0,0 +1,101 @@
+.. _zend.cache.pattern.output-cache:
+
+Zend\\Cache\\Pattern\\OutputCache
+=================================
+
+.. _zend.cache.pattern.output-cache.overview:
+
+Overview
+--------
+
+The ``OutputCache`` pattern caches output between calls to ``start()`` and ``end()``.
+
+.. _zend.cache.pattern.output-cache.quick-start:
+
+Quick Start
+-----------
+
+Instantiating the output cache pattern
+
+.. code-block:: php
+ :linenos:
+
+ use Zend\Cache\PatternFactory;
+
+ $outputCache = PatternFactory::factory('output', array(
+ 'storage' => 'apc'
+ ));
+
+.. _zend.cache.pattern.output-cache.options:
+
+Configuration options
+---------------------
+
++--------+-------------------------------------------------------------+--------------+--------------------------------------+
+|Option |Data Type |Default Value |Description |
++========+=============================================================+==============+======================================+
+|storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
++--------+-------------------------------------------------------------+--------------+--------------------------------------+
+
+.. _zend.cache.pattern.output-cache.methods:
+
+Available Methods
+-----------------
+
+.. _zend.cache.pattern.output-cache.methods.start:
+
+**start**
+ ``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.
+
+ Returns boolean
+
+.. _zend.cache.pattern.output-cache.methods.end:
+
+**end**
+ ``end()``
+
+ Stops buffering output, write buffered data to cache using the given key on start()
+ and displays the buffer.
+
+ Returns boolean
+
+.. _zend.cache.pattern.output-cache.methods.set-options:
+
+**setOptions**
+ ``setOptions(Zend\Cache\Pattern\PatternOptions $options)``
+
+ Set pattern options
+
+ Returns Zend\\Cache\\Pattern\\OutputCache
+
+.. _zend.cache.pattern.output-cache.methods.get-options:
+
+**getOptions**
+ ``getOptions()``
+
+ Get all pattern options
+
+ Returns ``PatternOptions`` instance.
+
+.. _zend.cache.pattern.pattern-factory.examples:
+
+Examples
+--------
+
+.. _zend.cache.pattern.output-cache.examples.caching-simple-views:
+
+.. rubric:: Caching simple view scripts
+
+.. code-block:: php
+ :linenos:
+
+ $outputCache = Zend\Cache\PatternFactory::factory('output', array(
+ 'storage' => 'apc',
+ ));
+
+ $outputCache->start('mySimpleViewScript');
+ include '/path/to/view/script.phtml';
+ $outputCache->end();
274 docs/languages/en/modules/zend.cache.pattern.rst
View
@@ -3,7 +3,7 @@
Zend\\Cache\\Pattern
====================
-.. _zend.cache.pattern.intro:
+.. _zend.cache.pattern.overview:
Overview
--------
@@ -13,8 +13,8 @@ specific situations they are designed to address. For example you can use one of
``ObjectCache`` or ``ClassCache`` patterns to cache method and function calls; to cache output generation, the
``OutputCache`` pattern could assist.
-All cache patterns implements the same interface, ``Zend\Cache\Pattern``, and most extend the abstract class
-``Zend\Cache\Pattern\AbstractPattern`` to implement basic logic.
+All cache patterns implements the same interface, ``Zend\Cache\Pattern\PatternInterface``, and most extend the abstract
+class ``Zend\Cache\Pattern\AbstractPattern`` to implement basic logic.
Configuration is provided via the ``Zend\Cache\Pattern\PatternOptions`` class, which can simply be instantiated
with an associative array of options passed to the constructor. To configure a pattern object, you can set an
@@ -30,153 +30,31 @@ Quick Start
-----------
Pattern objects can either be created from the provided ``Zend\Cache\PatternFactory`` factory, or, by simply
-instantiating one of the ``Zend\Cache\Pattern\*`` classes.
+instantiating one of the ``Zend\Cache\Pattern\*Cache`` classes.
.. code-block:: php
:linenos:
- use Zend\Cache\PatternFactory;
- use Zend\Cache\Pattern\PatternOptions;
-
// Via the factory:
- $callbackCache = PatternFactory::factory('callback', array(
- 'storage' => 'apc',
- 'cache_output' => true,
+ $callbackCache = Zend\Cache\PatternFactory::factory('callback', array(
+ 'storage' => 'apc',
));
+
+.. code-block:: php
+ :linenos:
// OR, the equivalent manual instantiation:
- $callbackCache = new \Zend\Cache\Pattern\CallbackCache();
- $callbackCache->setOptions(new PatternOptions(array(
- 'storage' => 'apc',
- 'cache_output' => true,
+ $callbackCache = new Zend\Cache\Pattern\CallbackCache();
+ $callbackCache->setOptions(new Zend\Cache\Pattern\PatternOptions(array(
+ 'storage' => 'apc',
)));
-.. _zend.cache.pattern.callbackcache:
-
-Zend\\Cache\\Pattern\\CallbackCache
------------------------------------
-
- This cache pattern caches calls of not specific functions and methods given as a callback.
-
-.. _zend.cache.pattern.callbackcache.options:
-
-.. table:: Configuration options
-
- +--------------+--------------------------------------------------------------+----------------+-------------------------------------------------+
- |Option |Data Type |Default Value |Description |
- +==============+==============================================================+================+=================================================+
- |storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
- +--------------+--------------------------------------------------------------+----------------+-------------------------------------------------+
- |cache_output |``boolean`` |``true`` |Cache output of callback |
- +--------------+--------------------------------------------------------------+----------------+-------------------------------------------------+
-
-.. _zend.cache.pattern.classcache:
-
-Zend\\Cache\\Pattern\\ClassCache
---------------------------------
-
- This cache pattern caches calls of static class methods.
-
-.. _zend.cache.pattern.classcache.options:
-
-.. table:: Configuration options
-
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |Option |Data Type |Default Value |Description |
- +========================+==============================================================+================+=================================================================+
- |storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |class |``string`` |<none> |The class name |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |cache_output |``boolean`` |``true`` |Cache output of callback |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |cache_by_default |``boolean`` |``true`` |Cache method calls by default |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |class_cache_methods |``array`` |``[]`` |List of methods to cache (If ``cache_by_default`` is disabled) |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
- |class_non_cache_methods |``array`` |``[]`` |List of methods to no-cache (If ``cache_by_default`` is enabled) |
- +------------------------+--------------------------------------------------------------+----------------+-----------------------------------------------------------------+
-
-.. _zend.cache.pattern.objectcache:
-
-Zend\\Cache\\Pattern\\ObjectCache
----------------------------------
-
- This cache pattern caches calls of object methods.
-
-.. _zend.cache.pattern.objectcache.options:
-
-.. table:: Configuration options
-
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |Option |Data Type |Default Value |Description |
- +==============================+==============================================================+========================+=================================================================+
- |storage |``string`` ``array`` ``Zend\Cache\Storage\StorageInterface`` |<none> |The storage to write/read cached data |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |object |``object`` |<none> |The object to cache methods calls of |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |object_key |``null`` ``string`` |<Class name of object> |A hopefully unique key of the object |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |cache_output |``boolean`` |``true`` |Cache output of callback |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |cache_by_default |``boolean`` |``true`` |Cache method calls by default |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |object_cache_methods |``array`` |``[]`` |List of methods to cache (If ``cache_by_default`` is disabled) |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |object_non_cache_methods |``array`` |``[]`` |List of methods to no-cache (If ``cache_by_default`` is enabled) |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
- |object_cache_magic_properties |``boolean`` |``false`` |Cache calls of magic object properties |
- +------------------------------+--------------------------------------------------------------+------------------------+-----------------------------------------------------------------+
-
-.. _zend.cache.pattern.capturecache:
-
-Zend\\Cache\\Pattern\\CaptureCache
-----------------------------------
-
- This cache pattern writes the output of the script to the requested file.
- So for next requests the webserver can response with a static file
- instead of starting PHP again to generate the response again.
-
-.. _zend.cache.pattern.capturecache.options:
-
-.. table:: 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 generationg output files / directories |
- +------------------+--------------------------+------------------------+-----------------------------------------------------------------+
-
-.. _zend.cache.pattern.capturecache:
-
-Zend\\Cache\\Pattern\\OutputCache
-----------------------------------
-
- This cache pattern caches script output between calls to ``start(string $key)`` and ``end()``.
-
-.. _zend.cache.pattern.outputcache.options:
-
-.. table:: 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
-----------------
+The following methods are implemented by ``Zend\Cache\Pattern\AbstractPattern``.
+Please read documentation of specific patterns to get more information.
+
.. _zend.cache.pattern.methods.set-options:
**setOptions**
@@ -194,125 +72,3 @@ Available Methods
Get all pattern options
Returns ``PatternOptions`` instance.
-
-.. _zend.cache.pattern.examples:
-
-Examples
---------
-
-.. _zend.cache.pattern.examples.callback:
-
-.. rubric:: Using the callback cache pattern
-
-.. code-block:: php
- :linenos:
-
- use Zend\Cache\PatternFactory;
-
- $callbackCache = PatternFactory::factory('callback', array(
- 'storage' => 'apc'
- ));
-
- // Calls and caches the function doResourceIntensiceStuff with three arguments
- // and returns result
- $result = $callbackCache->call('doResourceIntensiveStuff', array(
- 'argument1',
- 'argument2',
- 'argumentN',
- ));
-
-.. _zend.cache.pattern.examples.object:
-
-.. rubric:: Using the object cache pattern
-
-.. code-block:: php
- :linenos:
-
- use Zend\Cache\PatternFactory;
-
- $object = new MyObject();
- $objectProxy = PatternFactory::factory('object', array(
- 'object' => $object,
- 'storage' => 'apc',
- ));
-
- // Calls and caches $object->doResourceIntensiveStuff with three arguments
- // and returns result
- $result = $objectProxy->doResourceIntensiveStuff('argument1', 'argument2', 'argumentN');
-
-.. _zend.cache.pattern.examples.class:
-
-.. rubric:: Using the class cache pattern
-
-.. code-block:: php
- :linenos:
-
- use Zend\Cache\PatternFactory;
-
- $classProxy = PatternFactory::factory('class', array(
- 'class' => 'MyClass',
- 'storage' => 'apc',
- ));
-
- // Calls and caches MyClass::doResourceIntensiveStuff with three arguments
- // and returns result
- $result = $classProxy->doResourceIntensiveStuff('argument1', 'argument2', 'argumentN');
-
-.. _zend.cache.pattern.examples.output:
-
-.. rubric:: Using the output cache pattern
-
-.. code-block:: php
- :linenos:
-
- use Zend\Cache\PatternFactory;
-
- $outputCache = PatternFactory::factory('output', array(
- 'storage' => 'filesystem',
- ));
-
- // Start capturing all output (excluding headers) and write it to storage.
- // If there is already a cached item with the same key it will be
- // output and return true, else false.
- if ($outputCache->start('MyUniqueKey') === false) {
- echo 'cache output since: ' . date('H:i:s') . "<br />\n";
-
- // end capturing output, write content to cache storage and display
- // captured content
- $outputCache->end();
- }
-
- echo 'This output is never cached.';
-
-.. _zend.cache.pattern.examples.capture:
-
-.. rubric:: Using the capture cache pattern
-
-You need to configure your HTTP server to redirect missing content to run your script generating it.
-
-This example uses Apache with the following .htaccess:
-
-.. code-block:: text
- :linenos:
-
- ErrorDocument 404 /index.php
-
-Within your index.php you can add the following content:
-
-.. code-block:: php
- :linenos:
-
- use Zend\Cache\PatternFactory;
-
- $capture = PatternFactory::factory('capture', array(
- 'public_dir' => __DIR__,
- ));
-
- // Start capturing all output excl. headers. and write to public directory
- // If the request was already written the file will be overwritten.
- $capture->start();
-
- // do stuff to dynamically generate output
-
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.