Skip to content

Commit fb54b41

Browse files
committed
added quuery params to cache key
1 parent 1b12389 commit fb54b41

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Routing/RouterListener.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,34 @@ public function onAfterRouting(GetResponseEvent $event)
8888
*/
8989
private function createCacheKey(Request $request)
9090
{
91-
$key = 'route_'.$request->getMethod().'_'.$request->getHost().'_'.$request->getPathInfo();
91+
$key = sprintf('route:%s:%s:%s',$request->getMethod(),$request->getHost(),$request->getPathInfo());
92+
93+
// This might be optional
94+
$key.=':'.$this->implodeRecursive('|', $request->query->all());
9295

9396
return $key;
9497
}
9598

99+
/**
100+
* @param $separator
101+
* @param array $array
102+
*
103+
* @return string
104+
*/
105+
private function implodeRecursive($separator, array $array)
106+
{
107+
$output = '';
108+
foreach ($array as $key=>$value) {
109+
if (is_array($value)) {
110+
$output.=sprintf('%s%s[%s]', $separator, $key, $this->implodeRecursive($separator, $value));
111+
} else {
112+
$output.=$separator.$value;
113+
}
114+
}
115+
116+
return ltrim($output, $separator);
117+
}
118+
96119
/**
97120
* @param Request $request
98121
*

0 commit comments

Comments
 (0)