@@ -36,11 +36,10 @@ protected function acknowledgeEsiSupport(Response $response)
36
36
* the response as a cacheable content.
37
37
*
38
38
* @param \Symfony\Component\HttpFoundation\Response $response
39
- * @param int $cacheDuration
40
39
*/
41
- protected function addCacheableHeader (Response $ response, $ cacheDuration )
40
+ protected function addCacheableHeader (Response $ response )
42
41
{
43
- $ duration = $ this ->getCacheDuration (( int ) $ cacheDuration );
42
+ $ duration = $ this ->getCacheDuration ();
44
43
45
44
$ response ->headers ->set ($ this ->getConfig ('cacheable_header ' ), '1 ' );
46
45
$ response ->headers ->set ('Cache-Control ' , 'public, max-age= ' .$ duration );
@@ -60,43 +59,49 @@ public function addUncacheableHeader(Response $response)
60
59
}
61
60
62
61
/**
63
- * Normalize the given cache duration and convert
62
+ * Normalize the cache duration value and convert
64
63
* it to seconds.
65
64
*
66
- * @param int $duration
67
- *
68
65
* @return int|float
69
66
*/
70
- protected function getCacheDuration ($ duration )
67
+ protected function getCacheDuration ()
71
68
{
72
- $ cacheInMinutes = ($ duration > 0 ) ? $ duration : $ this ->getConfig ('cache_duration ' );
73
-
74
- return $ cacheInMinutes * 60 ;
69
+ return $ this ->getConfig ('cache_duration ' ) * 60 ;
75
70
}
76
71
77
72
/**
78
73
* Manipulate the current Http response.
79
74
*
80
75
* @param \Symfony\Component\HttpFoundation\Response $response
81
- * @param int $cacheDuration
82
76
*
83
77
* @return \Symfony\Component\HttpFoundation\Response
84
78
*/
85
- public function manipulate (Response $ response, $ cacheDuration )
79
+ public function manipulate (Response $ response )
86
80
{
87
81
$ this ->acknowledgeEsiSupport ($ response );
88
82
89
83
if ($ this ->shouldNotCache ($ response )) {
90
84
return $ response ;
91
85
}
92
86
93
- $ this ->addCacheableHeader ($ response, $ cacheDuration );
87
+ $ this ->addCacheableHeader ($ response );
94
88
$ this ->addLastModifiedHeader ($ response );
95
89
$ this ->addEtagHeader ($ response );
96
90
97
91
return $ response ;
98
92
}
99
93
94
+ /**
95
+ * Set cache duration value in minutes. This value will
96
+ * be added to the HTTP response's Cache-Control header.
97
+ *
98
+ * @param int $duration [Cache duration value in minutes]
99
+ */
100
+ public function setCacheDuration ($ duration )
101
+ {
102
+ $ this ->setConfig ('cache_duration ' , (int ) $ duration );
103
+ }
104
+
100
105
/**
101
106
* Set the current Http request headers.
102
107
*
@@ -145,4 +150,14 @@ abstract protected function addLastModifiedHeader(Response $response);
145
150
* @return mixed
146
151
*/
147
152
abstract public function getConfig ($ key );
153
+
154
+ /**
155
+ * Set configuration value for a specific key.
156
+ *
157
+ * @param string $key
158
+ * @param mixed $value
159
+ *
160
+ * @return void
161
+ */
162
+ abstract public function setConfig ($ key , $ value );
148
163
}
0 commit comments