@@ -14,6 +14,136 @@ HttpRedisCache is only supported by symfony 2.3 . Any other versions may or may
14
14
15
15
Installation
16
16
------------
17
+ Add HttpRedisCache to your application's ` composer.json ` file
18
+ ``` json
19
+ {
20
+ "require" : {
21
+ "solilokiam/httprediscache" : " dev-master"
22
+ }
23
+ }
24
+
25
+ Install the library and it's dependencies using the following command:
26
+ ```bash
27
+ $ php composer.phar update solilokiam\httprediscache
28
+ ```
29
+
30
+ Activate your symfony (internal http cache)[ http://symfony.com/doc/current/book/http_cache.html#symfony2-reverse-proxy ] :
31
+ ``` php
32
+ // web/app.php
33
+ require_once __DIR__.'/../app/bootstrap.php.cache';
34
+ require_once __DIR__.'/../app/AppKernel.php';
35
+ require_once __DIR__.'/../app/AppCache.php';
36
+
37
+ use Symfony\Component\HttpFoundation\Request;
38
+
39
+ $kernel = new AppKernel('prod', false);
40
+ $kernel->loadClassCache();
41
+ // wrap the default AppKernel with the AppCache one
42
+ $kernel = new AppCache($kernel);
43
+ $request = Request::createFromGlobals();
44
+ $response = $kernel->handle($request);
45
+ $response->send();
46
+ $kernel->terminate($request, $response);
47
+ ```
48
+
49
+ Make ` AppCache ` class extend HttpRedisCache instead on HttpCache like this:
50
+ ``` php
51
+ // app/AppCache.php
52
+ require_once __DIR__.'/AppKernel.php';
53
+
54
+
55
+ class AppCache extends \Solilokiam\HttpRedisCache\HttpRedisCache
56
+ {
57
+
58
+ }
59
+ ```
60
+
61
+ Configuration
62
+ -------------
63
+ By default this library has the following configuration:
64
+ - redis host: localhost
65
+ - redis port: 6379
66
+ - redis password: ~
67
+ - redis database: ~
68
+ - redis options: ~
69
+
70
+ You can change it adding some method implementations in ` AppCache ` :
71
+ ``` php
72
+ // app/AppCache.php
73
+ require_once __DIR__.'/AppKernel.php';
74
+
75
+
76
+ class AppCache extends \Solilokiam\HttpRedisCache\HttpRedisCache
77
+ {
78
+ public function getConnectionParams()
79
+ {
80
+ return array(
81
+ 'host' => 'localhost',
82
+ 'port' => '6739',
83
+ 'password' => 'somepassword',
84
+ 'database' => 'somedatabase',
85
+ 'options' => array(
86
+ Redis::OPT_SERIALIZER => Redis::SERIALIZER_NONE,
87
+ Redis::OPT_PREFIX => 'myAppName:'
88
+ )
89
+ );
90
+ }
91
+ }
92
+ ```
93
+
94
+ The only * required* array element is host others are optional.
95
+
96
+ You can also configure key prefixes adding some implementation methods in ` AppCache ` :
97
+ ``` php
98
+ // app/AppCache.php
99
+ require_once __DIR__.'/AppKernel.php';
100
+
101
+
102
+ class AppCache extends \Solilokiam\HttpRedisCache\HttpRedisCache
103
+ {
104
+ ...
105
+
106
+ public function getDigestKeyPrefix()
107
+ {
108
+ return 'hrd';
109
+ }
110
+
111
+ public function getLockKey()
112
+ {
113
+ return 'hrl';
114
+ }
115
+
116
+ public function getMetadataKeyPrefix()
117
+ {
118
+ return 'hrm';
119
+ }
120
+ ...
121
+ }
122
+ ```
123
+
124
+ Remember that you can configure other cache settings the sameway you do with default symfony internal http cache.
125
+ ``` php
126
+ // app/AppCache.php
127
+ use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
128
+
129
+ class AppCache extends HttpCache
130
+ {
131
+ protected function getOptions()
132
+ {
133
+ return array(
134
+ 'debug' => false,
135
+ 'default_ttl' => 0,
136
+ 'private_headers' => array('Authorization', 'Cookie'),
137
+ 'allow_reload' => false,
138
+ 'allow_revalidate' => false,
139
+ 'stale_while_revalidate' => 2,
140
+ 'stale_if_error' => 60,
141
+ );
142
+ }
143
+ }
144
+ ```
145
+
146
+
17
147
18
148
Author
19
149
------
0 commit comments