Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
a9ff89d1
Commit
a9ff89d1
authored
May 09, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added HttpCacheExtension
parent
d4028343
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
0 deletions
+116
-0
doc/extensions.rst
doc/extensions.rst
+1
-0
doc/extensions/http_cache.rst
doc/extensions/http_cache.rst
+75
-0
src/Silex/Extension/HttpCacheExtension.php
src/Silex/Extension/HttpCacheExtension.php
+40
-0
No files found.
doc/extensions.rst
View file @
a9ff89d1
...
@@ -65,6 +65,7 @@ All of these are within the ``Silex\Extension`` namespace.
...
@@ -65,6 +65,7 @@ All of these are within the ``Silex\Extension`` namespace.
* :doc:`TranslationExtension <extensions/translation>`
* :doc:`TranslationExtension <extensions/translation>`
* :doc:`UrlGeneratorExtension <extensions/url_generator>`
* :doc:`UrlGeneratorExtension <extensions/url_generator>`
* :doc:`ValidatorExtension <extensions/validator>`
* :doc:`ValidatorExtension <extensions/validator>`
* :doc:`HttpCacheExtension <extensions/http_cache>`
Creating an extension
Creating an extension
---------------------
---------------------
...
...
doc/extensions/http_cache.rst
0 → 100644
View file @
a9ff89d1
HttpCacheExtension
==================
The *HttpCacheExtension* provides support for the Symfony2 Reverse Proxy.
Parameters
----------
* **http_cache.cache_dir**: The cache directory to store the HTTP cache data.
* **http_cache.options** (optional): An array of options for the `HttpCache
<http:
//
api
.
symfony
.
com
/
2
.
0
/
Symfony
/
Component
/
HttpKernel
/
HttpCache
/
HttpCache
.
html
>
`_
constructor.
Services
--------
* **http_cache**: An instance of `HttpCache
<http:
//
api
.
symfony
.
com
/
2
.
0
/
Symfony
/
Component
/
HttpKernel
/
HttpCache
/
HttpCache
.
html
>
`_,
Registering
-----------
::
$app->register(new Silex\Extension\HttpCacheExtension(), array(
'cache_dir' => __DIR__.'/cache/',
));
Usage
-----
Silex already supports any Reverse Proxy like Varnish out of the box by
setting Response HTTP cache headers:
$app->get('/', function() {
return new Response('Foo', 200, array(
'Cache-Control' => 's-maxage=5',
));
});
This extension allows you to use the Symfony2 reverse proxy natively with
Silex applications by using the `http_cache` service to handle the Request::
$app['http_cache']->handle($request)->send();
The extension also provide `ESI
<http:
//
www
.
doctrine-project
.
org
/
docs
/
dbal
/
2
.
0
/
en
/>
`_ support::
$app->get('/', function() {
return new Response(
<
<<
EOF
<
html
>
<body>
Hello
<esi:include
src=
"/included"
/>
</body>
</html>
EOF
, 200, array(
'Cache-Control' => 's-maxage=20',
'Surrogate-Control' => 'content="ESI/1.0"',
));
});
$app->get('/included', function() {
return new Response('Foo', 200, array(
'Cache-Control' => 's-maxage=5',
));
});
$app['http_cache']->handle($request)->send();
For more information, consult the `Symfony2 HTTP Cache documentation
<http:
//
symfony
.
com
/
doc
/
current
/
book
/
http_cache
.
html
>
`_.
src/Silex/Extension/HttpCacheExtension.php
0 → 100644
View file @
a9ff89d1
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex\Extension
;
use
Silex\Application
;
use
Silex\ExtensionInterface
;
use
Symfony\Component\HttpKernel\HttpCache\HttpCache
;
use
Symfony\Component\HttpKernel\HttpCache\Esi
;
use
Symfony\Component\HttpKernel\HttpCache\Store
;
class
HttpCacheExtension
implements
ExtensionInterface
{
public
function
register
(
Application
$app
)
{
$app
[
'http_cache'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
HttpCache
(
$app
,
$app
[
'http_cache.store'
],
$app
[
'http_cache.esi'
],
$app
[
'http_cache.options'
]);
});
$app
[
'http_cache.esi'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
Esi
();
});
$app
[
'http_cache.store'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
Store
(
$app
[
'http_cache.cache_dir'
]);
});
if
(
!
isset
(
$app
[
'http_cache.options'
]))
{
$app
[
'http_cache.options'
]
=
array
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment