Cache in CDN but not in browser
Asked Answered
A

2

14

I currently use Akamai as a CDN, but I noticed that the browser is also caching content. It's great that the browser caches images/css/js, but I would like to know if there is a way to not cache on the browser, but to cache in Akamai.

Now, right now from my origin I send headers like this:

Cache-Control: public, must-revalidate, max-age=300
Expires: Sun, 19 Feb 2012 19:04:30 GMT
Date: Sun, 19 Feb 2012 18:59:30 GMT

Akamai honors these headers, but also passes them right back to the user. This makes it so the browser actually caches the content also.

This works great most of the time, but we also have some CDN logic that if a user has a logged in cookie, to bypass the CDN cache and go right to origin.

So, if let's say an un-authed user is on a clicks "login", they are then sent through the login process and brought back to the same page. Even though the CDN would request from origin for this page, the browser actually requests the same page again and it looks as if the login hasn't worked.

Now, I can force that a login process adds a query param like ?l=1 or something, but there has to be a better way.

I'm tempted to see if Akamai can overwrite the the Cache-Control header to a hard coded no-cache value, but I'm wondering if there is a way to do this in origin?

Thanks!

Anis answered 19/2, 2012 at 19:5 Comment(2)
Why do you want to stop the browser from caching the content?Abad
Because he wants the browser to re-download the page when the user is logged in. Probably so that the user will see a personalized page and not the same html that everyone else would get.Autotype
P
21

Akamai has a header called "Edge-control" of the same format as Cache-Control. You can specify the Edge-control with a positive max-age and then set Cache-Control to "no-cache, no-store". This should get what you want.

When sending the Edge-control header for a page I want cached, I always precede the value with "!no-store" to make sure Akamai caches it. So the format would be "!no-store,max-age=1234" for instance.

Pricking answered 25/5, 2012 at 20:18 Comment(0)
S
3

Akamai does provide a means to set different caching behaviour within the Akamai servers vs the usual Cache-Control: and Expires: headers. There are custom headers you can pass from your origin servers that the Akamai edge servers understand, obey and strip when they pass the content on to the browser. This information is available within the Akamai portal documentation.

In your case you want the behaviour to change depending on whether a user is logged in or not. You can ask that that the object bypasses the cache when the object is being delivered to the browser for logged in users or you could use cookie values to modify the cache key (how the object is referenced by the Akamai server), but you may need to speak with Akamai for help here.

You will need to be very careful here to ensure that something personalised cannot be viewed by other users of the Akamai cache. If in doubt, err on the side of caution and don't allow Akamai to cache the object.

Sheeree answered 23/3, 2012 at 3:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.