Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Classes/Middleware/RequestCacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ class RequestCacheMiddleware implements MiddlewareInterface
*/
protected $ignoredQueryParams;

/**
* @var array
* @Flow\InjectConfiguration(path="request.queryParams.ignorePrefix")
*/
protected $ignoredQueryPrefix;

/**
* @var array
* @Flow\InjectConfiguration(path="request.cookieParams.ignore")
*/
protected $ignoredCookieParams;

/**
* @var array
* @Flow\InjectConfiguration(path="request.cookieParams.ignorePrefix")
*/
protected $ignoredCookiePrefix;

/**
* @var boolean
* @Flow\InjectConfiguration(path="maxPublicCacheTime")
Expand Down Expand Up @@ -136,6 +148,9 @@ protected function getCacheIdentifierForRequestIfCacheable(ServerRequestInterfac
case (in_array($key, $this->ignoredQueryParams)):
$ignoredQueryParams[$key] = $value;
break;
case (array_reduce($this->ignoredQueryPrefix, fn ($carry, $prefix) => $carry || strpos($key, $prefix) === 0, false)):
$ignoredQueryParams[$key] = $value;
break;
default:
$disallowedQueryParams[$key] = $value;
}
Expand All @@ -148,7 +163,8 @@ protected function getCacheIdentifierForRequestIfCacheable(ServerRequestInterfac
$requestCookieParams = $request->getCookieParams();
$disallowedCookieParams = [];
foreach ($requestCookieParams as $key => $value) {
if (!in_array($key, $this->ignoredCookieParams)) {
$prefixed = array_reduce($this->ignoredCookiePrefix, fn ($carry, $prefix) => $carry || strpos($key, $prefix) === 0, false);
if (!in_array($key, $this->ignoredCookieParams) && !$prefixed) {
$disallowedCookieParams[$key] = $value;
}
}
Expand Down
10 changes: 10 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Flowpack:
# if they are only used on the client side
ignore: []

# ignored cookie params based on prefix exclude cookies that are handled by the frontend
# and are not relevant for the backend. A usecase would be affiliate cookies which are
# dynamically generated if they are only used on the client side
ignorePrefix: []

# a request will only qualify for caching if it only contains queryParams that
# are allowed or ignored. All other arguments will prevent caching.
queryParams:
Expand All @@ -31,6 +36,11 @@ Flowpack:
# the backend like utm_campaign
ignore: []

# ignored prefix arguments are not part of the cache identifier but do not
# prevent caching either. Use this for arguments that are meaningless for
# the backend like utm_
ignorePrefix: []

Neos:
Flow:
http:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Flowpack:
# and are not relevant for the backend. A usecase would be gdpr consent cookies
# if they are only used on the client side
ignore: []

# ignored cookie params based on prefix exclude cookies that are handled by the frontend
# and are not relevant for the backend. A usecase would be affiliate cookies which are
# dynamically generated if they are only used on the client side
ignorePrefix: []

# a request will only qualify for caching if it only contains queryParams that
# are allowed or ignored. All other arguments will prevent caching.
Expand All @@ -43,6 +48,11 @@ Flowpack:
# prevent caching either. Use this for arguments that are meaningless for
# the backend like utm_campaign
ignore: []

# ignored prefix arguments are not part of the cache identifier but do not
# prevent caching either. Use this for arguments that are meaningless for
# the backend like utm_
ignorePrefix: []
```

You can also move the cache backend to something faster if available, to improve performance even more.
Expand Down