Wildcard support for cookies in the HTTP cache

Christopher Skene
17 Oct 2017
Thumbnail

Platform.sh now supports regular expressions for wildcard cookie matching at the cache layer.

Platform.sh Professional includes a dynamic HTTP cache that allows you to cache responses from your application based on the headers and cookies that you specify. This gives you better performance by caching pages or assets which do not change often or per user (if you're on Platform.sh Enterprise, you already have access to a powerful global application cache and CDN, so this is not required).

Until recently, you were limited in control the cache to using only fixed cookie names. This meant, for example, that if you were using a session cookie to keep users logged in, that you had to keep track of all the session cookie names used in all your environments or disable the HTTP cache for all users. It also made it difficult to set up useful caching rules when you were using third-party cookies like those set by Google Analytics.

Well, you don’t have to worry anymore, because Platform.sh now supports regular expressions for wildcard cookie matching at the cache layer. This allows you to be very specific about which cookies you cache on and which you let through to the backend, giving you full flexibility in caching.

Users of Drupal, Wordpress and other systems where the cookie name is per user will get the most benefit from this new behaviour, which effectively enables full caching for users who aren’t logged in. Here’s an example for users of Drupal which allows the session cookie through...

https://{default}/:
    type: upstream
    upstream: app:http
    cache:
        enabled: true
        cookies: ['/^SS?ESS/']

Adding a regular expression match to your existing routes is very easy and only takes a couple of minutes. Just remember to test it in a development environment first.

Full details are available in our documentation.