Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
.*.sw*
.*.un~
nbproject
doc/html/
tmp/
zf-mkdoc-theme/

clover.xml
composer.lock
Expand Down
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ branches:
cache:
directories:
- $HOME/.composer/cache
- $HOME/.local
- zf-mkdoc-theme

services:
- memcached
Expand All @@ -31,6 +33,11 @@ env:
- TESTS_ZEND_CACHE_REDIS_PORT: 6379
- TESTS_ZEND_CACHE_REDIS_PASSWORD: ""
- TESTS_ZEND_CACHE_REDIS_DATABASE: 0
- SITE_URL: https://zendframework.github.io/zend-cache
- GH_USER_NAME: "Matthew Weier O'Phinney"
- GH_USER_EMAIL: [email protected]
- GH_REF: github.com/zendframework/zend-cache.git
- secure: "ZYYlfFWTde5MCn6twsm/+s+mx4bLEaVFFG+tuaeiz7nCx+z495D6FxruzBbY1zheX9rNo9qReDo0Tyfn2wrUH8SJYbR9iKDqB95GPDDPW+I23Mw3Uuddr8XqbtabTJVqEQg6iAu7IIQG4TvFFmdq/g26jWim8Cngg/5zZh4Q2GuLSjIKRJBpLe7mSTjQVqaApS/a8wmvPJiSoqxWmY8Botc88ZXMmkRDPQoqEdZOeS4i029cGMXUnzGj7Vl7qwfol6Yj/R441Hd84Vt8P8BOdRyW0tjmllXLXJUYFKCcP5fEqIujbU68FwJMidCPzBcXv2N0klW43ViVwdJD6gBgZStwOyENGeEw1VcbZ6JReMa68F1mtqLhBhZtF8WRUI8+TYMYmLPGMVTcets4P3nIB18uX1CittwGDD2y2OL8MDvuIuaSQFoj/PdUb+BC/DvvmtPGnF6MLTAUjqNlxYbmzopufDEtivWHsqeyxHZj0L0HD5KkMslD9wnngfi+lcQ5e3iFQe/H5vQKE0BfooukxErIXk00cwwMoMjFY4v95CS0BKFhA4HMclKpGEA94CH4STxwyD2Nz/z6iGPqkZuzqDLOKhLr2FsY7bFbvEdNu57G3PGahtYJtc31lcnwKf2t1ALGcG9LS0/ezJSzqx659hWL0B5qgHjCNDnAyKJcNxM="

matrix:
fast_finish: true
Expand All @@ -48,6 +55,8 @@ matrix:
env:
- EXECUTE_TEST_COVERALLS=true
- PECL_INSTALL_APCU='apcu-4.0.8'
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- php: 5.6
env:
- SERVICE_MANAGER_VERSION="^2.7.5"
Expand Down Expand Up @@ -103,6 +112,10 @@ script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ storage adapters (DB, File, Memcache, etc).


- File issues at https://github.com/zendframework/zend-cache/issues
- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-cache
- Documentation is at https://zendframework.github.io/zend-cache/
11 changes: 11 additions & 0 deletions doc/book/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="container">
<div class="jumbotron">
<h1>zend-cache</h1>

<p>Caching implementation with a variety of storage options, as well as
codified caching strategies for callbacks, classes, and output.</p>

<pre><code class="language-bash">$ composer require zendframework/zend-cache</code></pre>
</div>
</div>

1 change: 1 addition & 0 deletions doc/book/index.md
92 changes: 92 additions & 0 deletions doc/book/pattern/callback-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# CallbackCache


The callback cache pattern caches the results of arbitrary PHP callables.

## Quick Start

```php
use Zend\Cache\PatternFactory;
use Zend\Cache\Pattern\PatternOptions;

// Via the factory:
$callbackCache = PatternFactory::factory('callback', [
'storage' => 'apc',
'cache_output' => true,
]);

// Or the equivalent manual instantiation:
$callbackCache = new \Zend\Cache\Pattern\CallbackCache();
$callbackCache->setOptions(new PatternOptions([
'storage' => 'apc',
'cache_output' => true,
]));
```

## Configuration Options

Option | Data Type | Default Value | Description
------ | --------- | ------------- | -----------
`storage` | `string | array | Zend\Cache\Storage\StorageInterface` | none | Adapter used for reading and writing cached data.
`cache_output` | `boolean` | `true` | Whether or not to cache callback output.

## Available Methods

In addition to the methods defined in the `PatternInterface`, this
implementation provides the following methods.

```php
namespace Zend\Cache\Pattern;

use Zend\Cache\Exception;
use Zend\Stdlib\ErrorHandler;

class CallbackCache extends AbstractPattern
{
/**
* Call the specified callback or get the result from cache
*
* @param callable $callback A valid callback
* @param array $args Callback arguments
* @return mixed Result
* @throws Exception\RuntimeException if invalid cached data
* @throws \Exception
*/
public function call($callback, array $args = []);

/**
* Intercept method overloading; proxies to call()
*
* @param string $function Function name to call
* @param array $args Function arguments
* @return mixed
* @throws Exception\RuntimeException
* @throws \Exception
*/
public function __call($function, array $args);

/**
* Generate a unique key in base of a key representing the callback part
* and a key representing the arguments part.
*
* @param callable $callback A valid callback
* @param array $args Callback arguments
* @return string
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
public function generateKey($callback, array $args = []);
}
```

## Examples

### Instantiating the callback cache pattern

```php
use Zend\Cache\PatternFactory;

$callbackCache = PatternFactory::factory('callback', [
'storage' => 'apc'
]);
```
145 changes: 145 additions & 0 deletions doc/book/pattern/capture-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# CaptureCache

The `CaptureCache` pattern is useful for generating static resources to return
via HTTP request. When used in such a fashion, the web server needs to be
configured to run a PHP script generating the requested resource so that
subsequent requests for the same resource can be shipped without calling PHP
again.

This pattern comes with basic logic for managing generated resources.

## Quick Start

For use with an Apache 404 handler:

```apacheconf
# .htdocs
ErrorDocument 404 /index.php
```

```php
// index.php
use Zend\Cache\PatternFactory;
$capture = Zend\Cache\PatternFactory::factory('capture', [
'public_dir' => __DIR__,
]);

// Start capturing all output, excluding headers, and write to the public
// directory:
$capture->start();

// Don't forget to change the 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 the public web root directory in which to write output.
`index_filename` | `string` | "index.html" | The name of the index file if only a directory was requested.
`file_locking` | `bool` | `true` | Whether or not to lock output files when writing.
`file_permission` | `int | bool` | `0600` (`false` on Windows) | Default permissions for generated output files.
`dir_permission` | `int | bool` | `0700` (`false` on Windows) | Default permissions for generated output directories.
`umask` | `int` | `bool` | `false` | Whether or not to umask generated output files / directories.

## Available Methods

In addition to the methods exposed in `PatternInterface`, this implementation
exposes the following methods.

```php
namespace Zend\Cache\Pattern;

use Zend\Cache\Exception;
use Zend\Stdlib\ErrorHandler;

class CaptureCache extends AbstractPattern
{
/**
* Start the cache.
*
* @param string $pageId Page identifier
* @return void
*/
public function start($pageId = null);

/**
* Write a page to the requested path.
*
* @param string $content
* @param null|string $pageId
* @throws Exception\LogicException
*/
public function set($content, $pageId = null);

/**
* Retrieve a generated page from the cache.
*
* @param null|string $pageId
* @return string|null
* @throws Exception\LogicException
* @throws Exception\RuntimeException
*/
public function get($pageId = null);

/**
* Check if a cache exists for the given page.
*
* @param null|string $pageId
* @throws Exception\LogicException
* @return bool
*/
public function has($pageId = null);

/**
* Remove a page from the cache.
*
* @param null|string $pageId
* @throws Exception\LogicException
* @throws Exception\RuntimeException
* @return bool
*/
public function remove($pageId = null);

/**
* Clear cached pages that match the specified glob pattern.
*
* @param string $pattern
* @throws Exception\LogicException
*/
public function clearByGlob($pattern = '**');

/**
* Returns the generated file name.
*
* @param null|string $pageId
* @return string
*/
public function getFilename($pageId = null);
}
```

## Examples

### Scaling images in the web root

Using the following Apache 404 configuration:

```apacheconf
# .htdocs
ErrorDocument 404 /index.php
```

Use the following script:

```php
// index.php
$captureCache = Zend\Cache\PatternFactory::factory('capture', [
'public_dir' => __DIR__,
]);

// TODO
```
Loading