[Radiant] Clearing caches on Heroku

476 views
Skip to first unread message

Charles Roper

unread,
Nov 30, 2009, 6:27:04 AM11/30/09
to rad...@radiantcms.org
I've been developing a Radiant-powered site on Heroku and have been having
difficulty with caching. When I save a page, the change will (usually) fail
to show up. Obviously I am aware that both Radiant and Heroku do some (quite
aggressive?) caching, so I was wondering if anyone could offer some advice
for when developing a site and the need for aggressive cache clearing is the
priority.

I've found logging into the heroku console and then clearing the cache to be
quite effective:

[ D:\Users\charlesr\Documents\My Dropbox\Projects\radiant_roast ]
> heroku console
Ruby console for foobarbaz.heroku.com
>> Radiant::Cache.clear
=> [#<Radiant::Cache::EntityStore:0x2b5c98de4a20
@root="/disk1/home/slugs/89730_0ada040_1fcc/mnt/tmp/cache/entity">]
>>

Is this the best way of tackling a cache refresh, or should I be doing
something else?

Cheers,
Charles
_______________________________________________
Radiant mailing list
Post: Rad...@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant

Sean Cribbs

unread,
Nov 30, 2009, 9:50:57 AM11/30/09
to rad...@radiantcms.org
That seems correct. I'm not sure about their other infrastructure, but
as of the current version, doing a hard-refresh in your browser will
cause the page to be purged from the cache as well.

Sean

Charles Roper

unread,
Dec 1, 2009, 4:50:56 AM12/1/09
to rad...@radiantcms.org
2009/11/30 Sean Cribbs <seanc...@gmail.com>

> That seems correct. I'm not sure about their other infrastructure, but
> as of the current version, doing a hard-refresh in your browser will
> cause the page to be purged from the cache as well.
>

Thanks Sean. When you say "as of the current version", you mean 0.8.1 rather
than the RC, right? I am using 0.8.1 and doing a hard refresh definitely
doesn't clear the cache properly. In fact, the behaviour can get quite
strange: repeated hard-refreshes can deliver any one of several revisions of
the same page. I am guessing each refresh must pulling data from different
dbs that haven't been sync'd. But that's just a guess; I've really no idea
what's going on. :)

Doing Radiant::Cache.clear in the heroku console definitely seems to help
matters, though.

Sean Cribbs

unread,
Dec 1, 2009, 8:25:43 AM12/1/09
to rad...@radiantcms.org

> Thanks Sean. When you say "as of the current version", you mean 0.8.1 rather
> than the RC, right? I am using 0.8.1 and doing a hard refresh definitely
> doesn't clear the cache properly. In fact, the behaviour can get quite
> strange: repeated hard-refreshes can deliver any one of several revisions of
> the same page. I am guessing each refresh must pulling data from different
> dbs that haven't been sync'd. But that's just a guess; I've really no idea
> what's going on. :)
>
>
I meant 0.8.x or later... things haven't changed with that in 0.9 RC1.
Your problem sounds like it's with Heroku's caching layer. Rack::Cache
tries to stay to the HTTP RFC in that it allows browser-initiated
refreshes to invalidate the cache (although this may be undesirable in
some cases, e.g. DDoS). Heroku likely has the "stale-while-invalid"
option in their cache, too, which is why you might be seeing different
versions randomly.

> Doing Radiant::Cache.clear in the heroku console definitely seems to help
> matters, though.
>
>
Good to know!

Sean

Charles Roper

unread,
Dec 2, 2009, 9:57:31 AM12/2/09
to rad...@radiantcms.org
Sean,

To round this discussion off, the Heroku docs say that the
Cache-Control header should be set to control the length of time a
page should stay in the cache:

http://docs.heroku.com/http-caching#caching-dynamic-content-by-age

Is it possible to control the max-age header in Radiant? If so, how?
Is it possible to set certain pages (and their children) to have a
discrete expiry? For instance, could I set the /news/ sub-tree with a
low 5 minute expiry and other sub-trees with a much higher expiry?

Cheers,
Charles

2009/12/1 Sean Cribbs <seanc...@gmail.com>:

Charles Roper

unread,
Dec 5, 2009, 11:11:53 AM12/5/09
to rad...@radiantcms.org
A little bit of further information for Radiant users on Heroku. This is
from Morten at Heroku:

---
I am not familiar with the particulars of Radiant caching. However,
Varnish can't be run clustered so our HTTP caching layer consists of n
individual Varnishes. You may see results propagating across the
Varnishes giving you an occasional stale hit. This is normal, and in
full usage on a busy site it's a very minor issue because it only takes
one request for the cached copy to update.

Also, the only way we have to purge the HTTP cache is heroku restart.
---

So, when I save a Radiant page/layout/snippet, the general process I
follow is this:

1. In the Heroku console, issue the Radiant::Cache.clear command and
hard-refresh in browser.

2. If changes still don't show, issue the heroku restart command and
hard-refresh again.

This seems to be a pretty robust way of clearing the Heroku and Radiant
caches. I've found that just doing step 1 seems to be enough, most of
the time.

As an aside, I've found Radiant running on Heroku to be a particularly
nice combination. Heroku's use of Varnish works exceedingly well with
Radiant, once you know how to bust the caches :). Once a page is cached
in Varnish, the backend doesn't get touched, so even with a free 1-dyno
account, you get really great performance.

This is possibly the most up-to-date tutorial, if anyone is interested:

http://j.mp/3ocDje [random facts girl: Radiant Heroku… getting your
Radiant App live on Heroku in about 10 minutes.]

Charles

Reply all
Reply to author
Forward
0 new messages