- Notifications
You must be signed in to change notification settings - Fork5
ZF2 module for automating http cache tasks within a Zend Framework 2 application.
License
zfcampus/zf-http-cache
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository has moved tolaminas-api-tools/api-tools-http-cache.
zf-http-cache is a ZF2 module for automating http-cache tasks within a Zend Framework 2application.
Run the followingcomposer command:
$composer require"zfcampus/zf-http-cache:^1.0"Alternately, manually add the following to yourcomposer.json, in therequire section:
"require":{"zfcampus/zf-http-cache":"^1.0"}
And then runcomposer update to ensure the module is installed.
Finally, add the module name to your project'sconfig/application.config.php under themoduleskey:
return [/* ... */'modules' => [/* ... */'ZF\HttpCache', ],/* ... */];
As a rule of thumb, avoid as much as possible using anonymous functions since it prevents you from caching your configuration.
The top-level configuration key for user configuration of this module iszf-http-cache.
Theconfig/module.config.php file contains a self-explanative example of configuration.
Thecontrollers key is utilized for mapping any of
- a route name
- a concatenated
controller::action - a controller
- a regexp
- a wildcard
Each is case sensitive, and will map one or more HTTP methods to the cacheheader configuration specific to the given rule.
Example:
// See `config/module.config.php` for a complete commented example'zf-http-cache' => [/* ... */'controllers' => ['<controller>' => ['<http-method>' => ['<cache-header-name>' => ['override' =>true,'value' =>'<cache-header-value>', ], ], ], ],/* ... */],
Either
- a concatenation of
$controller::$action - a controller name (as returned by
Zend\Mvc\MvcEvent::getRouteMatch()->getParam('controller');the value is case-sensitive) - a regexp (see
<regex_delimiter>key) - a wildcard
A wildcard matches any unspecified controllers.
Either a lower cased HTTP method (get,post, etc.) (as returned byZend\Http\Request::getMethod()) or a wildcard.
A wildcard stands for all the non-specified HTTP methods.
An HTTP cache header name (Cache-control,expires,etag etc.).
For ETags you can specify a custom generator in the configuration:
'etag' => [ 'override' => true, 'generator' => 'Your\Own\ETagGenerator',],A generator example can be found in\ZF\HttpCache\DefaultETagGenerator.
The value for the cache header.
Whether to override the cache headers possibly sent by your application.
Theenable key is utilized for enabling/disabling the http cache module at run time.
If you no longer need this module, rather consider removing the module from theapplication.config.php list.
Caution: when disabled, http cache module doesn't override/remove the cache headers sent by your application.
Example:
'zf-http-cache' => [/* ... */'enable' =>true,// Cache module is enabled./* ... */],
Thehttp_codes_black_list is utilized to avoid caching the responses with the listed HTTP status codes.Defaults to all others than200.
Example:
'zf-http-cache' => [/* ... */'http_codes_black_list' => ['201','304','400','500'],// Whatever the other configurations, the responses with these HTTP codes won't be cached./* ... */],
This key is used to enable the evaluation of the key as a regular expression.
It must contain the delimiter of the regular expression.
If you don't want to use regular expression in your configuration set this to null to avoid inutil parsing.
Regular expressions are tested in the very order they appear in the configuration, first matching wins.
Regexp wins over wildcard.
Caution: When this value is not empty and no litteral key corresponds to the current controller, a preg_match is used.
Example:
'zf-http-cache' => [/* ... */'regex_delimiter' =>'~',/* ... */'controllers' => ['~.*~' => [// Acts as a wildcard./* ... */ ], ],/* ... */],
The following configuration is provided inconfig/module.config.php:
'service_manager' => ['factories' => ['ZF\HttpCache\HttpCacheListener' =>'ZF\HttpCache\HttpCacheListenerFactory', ],],
This listener is attached to theMvcEvent::EVENT_ROUTE andMvcEvent::EVENT_FINISH events with the low priority of-10000.
About
ZF2 module for automating http cache tasks within a Zend Framework 2 application.
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- PHP100.0%