Re: [Radiant] Caching issue

2009-12-04 Thread Charles Roper
On 04/12/2009 00:47, Myron Marston wrote:

 The basic problem I ran into is that the Radiant cache isn't designed with
 regularly changing content (such as page ratings and comments) in mind.

Myron,

Thanks for this post. I've been trying to grok exactly how Radiant 
caches stuff and your message has certainly helped. I mentioned in a 
thread elsewhere[1] that it might be nice if a page and its children 
could be assigned a discrete max-age. Having read your post, it seems 
being able to manipulate the other cache control directives[2] would be 
good too.

Radiant is still new to me, though, so all this may be possible still.

[1] http://j.mp/8QTqPi
[2] http://j.mp/eLeHU

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


Re: [Radiant] Caching issue

2009-12-04 Thread Sean Cribbs
The thing that is kind of unintuitive about HTTP caching is the duality 
of it - both client and server are responsible.  This ultimately makes 
it very scalable, but (anti-?)patterns that we've grown accustomed to 
become difficult or confusing at best.

Without knowing the specifics of how the ratings extension works, I can 
tell you one way that you can invalidate the cache correctly: POST to 
the page that needs to be refreshed, and return the proper status code 
and headers.  In this case, both the cache and the client will recognize 
that the old version is invalid, and since it's a POST request, the 
cache won't store the result. This has worked very well in the comments 
extension, for example (see also: 
http://github.com/seancribbs/radiant-comments/blob/master/lib/comment_page_extensions.rb).

Sean

Myron Marston wrote:
 I found a solution to this today.  I wanted to update the list in case
 anyone else has this problem and also to get feedback.  I'm sure my solution
 can be improved.

 The basic problem I ran into is that the Radiant cache isn't designed with
 regularly changing content (such as page ratings and comments) in mind.  It
 sets the cache headers in the set_cache_control method:

 http://github.com/radiant/radiant/blob/b912a4e622fec974f7ae2d5e0acad1ad25fd06f8/app/controllers/site_controller.rb#L31-38

 This works great for static content such as radiant pages...if an admin
 changes the page, the user may still see the old version for up to the 5
 minute cache timeout, and that's not really that big of a deal.  But it
 breaks down when the user _immediately_ needs a fresh version of the page.
 When they rate a page or add a comment (I'm using both the ratings and
 comments extensions), its a bad user experience if their rating or new
 comment doesn't show up--it makes it appear as though it didn't work, and
 many users will re-submit their comment, leading to duplicates.

 The solution I found is to use the no-cache header, which, contrary to how
 it sounds, does allow a browser to cache a page, but instructs it to
 revalidate it with the server every time.  (see
 http://www.mnot.net/cache_docs/#CACHE-CONTROL for more details).  Then I use
 an ETag so a 304 Not Modified response is sent except when the page has
 changed.

 Here's the code:

 http://gist.github.com/d641725a48e0bf0dd5a8

 I'm just getting my feet wet with this HTTP caching stuff for the first
 time, so it's quite likely this is not an optimal solution, but it's working
 for me.  I'd welcome feedback if anyone has any suggestions for
 improvements.

 It strikes me that this is really something that the comments and ratings
 extensions should be handling, but Radiant doesn't provide hooks to make
 that easy.  Is that on the development roadmap?

 Myron

 On Mon, Nov 30, 2009 at 9:24 AM, Myron Marston myron.mars...@gmail.comwrote:

   
 I'm using (and improving) the ratings extension for use in my radiant 0.8.1
 app.  It works well except for a weird caching issue that I haven't been
 able to solve yet.

 When a user rates a page, the radiant cache is cleared, so that when they
 are redirected to the page, they get a fresh version of it that includes the
 new rating average.  On safari, this works as expected.  On firefox, I
 continue to get the old version of the page.  I have to manually refresh the
 page to force it to update the rating.

 I've investigated it a bit, and discovered that the cached entity and meta
 files are indeed being cleared at the right time.  My server logs show that
 when I rate a page using safari, it redirects to the page, and my server
 logs show a hit to SiteController#show_page, indicating that a fresh version
 of the page is being generated.  When I do this on firefox, it redirects,
 but there is not a hit to SiteController#show_page.  I just see a cached
 version of the page.

 So, it appears to me that the cache is being properly cleared on the
 server, but Firefox is continuing to display a version of the page that is
 has cached on the browser.  My best guess is that there is some issue with
 the HTTP cache headers that causes Firefox to continue to display it's
 cached page.  I haven't dealt with HTTP cache headers before, so I'm not
 really sure how to go about troubleshooting this.

 Any suggestions?

 Thanks,
 Myron

 
 ___
 Radiant mailing list
 Post:   Radiant@radiantcms.org
 Search: http://radiantcms.org/mailing-list/search/
 Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

   

___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


Re: [Radiant] Caching issue

2009-12-04 Thread Myron Marston
Sean,

My project is using both the ratings extension and the comments extension,
and I had the same problem with the comments extension.  I set the config
setting that causes comments to be posted to the page's URL (as you
recommended) and while it works great in Safari, it doesn't work in Firefox.
 In Firefox, the user gets an old version of the page without the comment
they have just submitted.

Maybe there's something else I don't have configured right?

Anyhow, for the time being I'm going to stick with my little etag hack.  The
site doesn't perform as well, but given that I don't expect much traffic,
I'll take correct behavior over faster performance.

Myron

On Fri, Dec 4, 2009 at 5:29 AM, Sean Cribbs seancri...@gmail.com wrote:

 The thing that is kind of unintuitive about HTTP caching is the duality
 of it - both client and server are responsible.  This ultimately makes
 it very scalable, but (anti-?)patterns that we've grown accustomed to
 become difficult or confusing at best.

 Without knowing the specifics of how the ratings extension works, I can
 tell you one way that you can invalidate the cache correctly: POST to
 the page that needs to be refreshed, and return the proper status code
 and headers.  In this case, both the cache and the client will recognize
 that the old version is invalid, and since it's a POST request, the
 cache won't store the result. This has worked very well in the comments
 extension, for example (see also:

 http://github.com/seancribbs/radiant-comments/blob/master/lib/comment_page_extensions.rb
 ).

 Sean

 Myron Marston wrote:
  I found a solution to this today.  I wanted to update the list in case
  anyone else has this problem and also to get feedback.  I'm sure my
 solution
  can be improved.
 
  The basic problem I ran into is that the Radiant cache isn't designed
 with
  regularly changing content (such as page ratings and comments) in mind.
  It
  sets the cache headers in the set_cache_control method:
 
 
 http://github.com/radiant/radiant/blob/b912a4e622fec974f7ae2d5e0acad1ad25fd06f8/app/controllers/site_controller.rb#L31-38
 
  This works great for static content such as radiant pages...if an admin
  changes the page, the user may still see the old version for up to the 5
  minute cache timeout, and that's not really that big of a deal.  But it
  breaks down when the user _immediately_ needs a fresh version of the
 page.
  When they rate a page or add a comment (I'm using both the ratings and
  comments extensions), its a bad user experience if their rating or new
  comment doesn't show up--it makes it appear as though it didn't work, and
  many users will re-submit their comment, leading to duplicates.
 
  The solution I found is to use the no-cache header, which, contrary to
 how
  it sounds, does allow a browser to cache a page, but instructs it to
  revalidate it with the server every time.  (see
  http://www.mnot.net/cache_docs/#CACHE-CONTROL for more details).  Then I
 use
  an ETag so a 304 Not Modified response is sent except when the page has
  changed.
 
  Here's the code:
 
  http://gist.github.com/d641725a48e0bf0dd5a8
 
  I'm just getting my feet wet with this HTTP caching stuff for the first
  time, so it's quite likely this is not an optimal solution, but it's
 working
  for me.  I'd welcome feedback if anyone has any suggestions for
  improvements.
 
  It strikes me that this is really something that the comments and ratings
  extensions should be handling, but Radiant doesn't provide hooks to make
  that easy.  Is that on the development roadmap?
 
  Myron
 
  On Mon, Nov 30, 2009 at 9:24 AM, Myron Marston myron.mars...@gmail.com
 wrote:
 
 
  I'm using (and improving) the ratings extension for use in my radiant
 0.8.1
  app.  It works well except for a weird caching issue that I haven't been
  able to solve yet.
 
  When a user rates a page, the radiant cache is cleared, so that when
 they
  are redirected to the page, they get a fresh version of it that includes
 the
  new rating average.  On safari, this works as expected.  On firefox, I
  continue to get the old version of the page.  I have to manually refresh
 the
  page to force it to update the rating.
 
  I've investigated it a bit, and discovered that the cached entity and
 meta
  files are indeed being cleared at the right time.  My server logs show
 that
  when I rate a page using safari, it redirects to the page, and my server
  logs show a hit to SiteController#show_page, indicating that a fresh
 version
  of the page is being generated.  When I do this on firefox, it
 redirects,
  but there is not a hit to SiteController#show_page.  I just see a cached
  version of the page.
 
  So, it appears to me that the cache is being properly cleared on the
  server, but Firefox is continuing to display a version of the page that
 is
  has cached on the browser.  My best guess is that there is some issue
 with
  the HTTP cache headers that causes Firefox to continue to display it's
  

Re: [Radiant] Caching issue

2009-12-03 Thread Myron Marston
I found a solution to this today.  I wanted to update the list in case
anyone else has this problem and also to get feedback.  I'm sure my solution
can be improved.

The basic problem I ran into is that the Radiant cache isn't designed with
regularly changing content (such as page ratings and comments) in mind.  It
sets the cache headers in the set_cache_control method:

http://github.com/radiant/radiant/blob/b912a4e622fec974f7ae2d5e0acad1ad25fd06f8/app/controllers/site_controller.rb#L31-38

This works great for static content such as radiant pages...if an admin
changes the page, the user may still see the old version for up to the 5
minute cache timeout, and that's not really that big of a deal.  But it
breaks down when the user _immediately_ needs a fresh version of the page.
When they rate a page or add a comment (I'm using both the ratings and
comments extensions), its a bad user experience if their rating or new
comment doesn't show up--it makes it appear as though it didn't work, and
many users will re-submit their comment, leading to duplicates.

The solution I found is to use the no-cache header, which, contrary to how
it sounds, does allow a browser to cache a page, but instructs it to
revalidate it with the server every time.  (see
http://www.mnot.net/cache_docs/#CACHE-CONTROL for more details).  Then I use
an ETag so a 304 Not Modified response is sent except when the page has
changed.

Here's the code:

http://gist.github.com/d641725a48e0bf0dd5a8

I'm just getting my feet wet with this HTTP caching stuff for the first
time, so it's quite likely this is not an optimal solution, but it's working
for me.  I'd welcome feedback if anyone has any suggestions for
improvements.

It strikes me that this is really something that the comments and ratings
extensions should be handling, but Radiant doesn't provide hooks to make
that easy.  Is that on the development roadmap?

Myron

On Mon, Nov 30, 2009 at 9:24 AM, Myron Marston myron.mars...@gmail.comwrote:

 I'm using (and improving) the ratings extension for use in my radiant 0.8.1
 app.  It works well except for a weird caching issue that I haven't been
 able to solve yet.

 When a user rates a page, the radiant cache is cleared, so that when they
 are redirected to the page, they get a fresh version of it that includes the
 new rating average.  On safari, this works as expected.  On firefox, I
 continue to get the old version of the page.  I have to manually refresh the
 page to force it to update the rating.

 I've investigated it a bit, and discovered that the cached entity and meta
 files are indeed being cleared at the right time.  My server logs show that
 when I rate a page using safari, it redirects to the page, and my server
 logs show a hit to SiteController#show_page, indicating that a fresh version
 of the page is being generated.  When I do this on firefox, it redirects,
 but there is not a hit to SiteController#show_page.  I just see a cached
 version of the page.

 So, it appears to me that the cache is being properly cleared on the
 server, but Firefox is continuing to display a version of the page that is
 has cached on the browser.  My best guess is that there is some issue with
 the HTTP cache headers that causes Firefox to continue to display it's
 cached page.  I haven't dealt with HTTP cache headers before, so I'm not
 really sure how to go about troubleshooting this.

 Any suggestions?

 Thanks,
 Myron

___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


[Radiant] Caching issue

2009-11-30 Thread Myron Marston
I'm using (and improving) the ratings extension for use in my radiant 0.8.1
app.  It works well except for a weird caching issue that I haven't been
able to solve yet.

When a user rates a page, the radiant cache is cleared, so that when they
are redirected to the page, they get a fresh version of it that includes the
new rating average.  On safari, this works as expected.  On firefox, I
continue to get the old version of the page.  I have to manually refresh the
page to force it to update the rating.

I've investigated it a bit, and discovered that the cached entity and meta
files are indeed being cleared at the right time.  My server logs show that
when I rate a page using safari, it redirects to the page, and my server
logs show a hit to SiteController#show_page, indicating that a fresh version
of the page is being generated.  When I do this on firefox, it redirects,
but there is not a hit to SiteController#show_page.  I just see a cached
version of the page.

So, it appears to me that the cache is being properly cleared on the server,
but Firefox is continuing to display a version of the page that is has
cached on the browser.  My best guess is that there is some issue with the
HTTP cache headers that causes Firefox to continue to display it's cached
page.  I haven't dealt with HTTP cache headers before, so I'm not really
sure how to go about troubleshooting this.

Any suggestions?

Thanks,
Myron
___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


Re: [Radiant] Caching issue

2009-11-30 Thread Anton Aylward
Myron Marston said the following on 11/30/2009 12:24 PM:

 
 So, it appears to me that the cache is being properly cleared on the server,
 but Firefox is continuing to display a version of the page that is has
 cached on the browser.  My best guess is that there is some issue with the
 HTTP cache headers that causes Firefox to continue to display it's cached
 page.  I haven't dealt with HTTP cache headers before, so I'm not really
 sure how to go about troubleshooting this.
 
 Any suggestions?

Perhaps this ties in with my Last-Modified header question.
Though in this case, I should think you have a simple case of changing
the header that has nothing to do with the time the page or its children
was edited.  However I'd be interested in hearing how you change it when
the page itself isn't edited.


-- 
Insanity is hereditary. You get it from your kids.
___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


Re: [Radiant] Caching issue

2009-11-30 Thread C. R. Oldham

On Nov 30, 2009, at 10:24 AM, Myron Marston wrote:

 I haven't dealt with HTTP cache headers before, so I'm not really
 sure how to go about troubleshooting this.
 
 Any suggestions?

Myron,

There are several extensions for Firefox that will let you view cache headers.  
Web Developer and Firebug both come to mind.  For Firebug, clear your cache, 
enable Firebug, click the Net tab in the Firebug panel and load the offending 
page in Firefox.  You should see an entry in the Net panel with a Headers tab.

--cro

___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


Re: [Radiant] Caching issue

2009-11-30 Thread Myron Marston

 Perhaps this ties in with my Last-Modified header question.


Anton--I looked through the archives and couldn't find this question.  I'd
be curious to read that thread if you can point me in the right direction.


 There are several extensions for Firefox that will let you view cache
 headers.  Web Developer and Firebug both come to mind.  For Firebug, clear
 your cache, enable Firebug, click the Net tab in the Firebug panel and
 load the offending page in Firefox.  You should see an entry in the Net
 panel with a Headers tab.


Thanks for the suggestion.  I should have a been a bit more specific
though...I know how to view the cache headers in safari and firefox, but I'm
still trying to wrap my head around how these headers work (I just read up
on them today for the first time), and I'm not sure what to try next.

One difference I'm seeing in the headers is that firefox sends a
HTTP_IF_NONE_MATCH header in its request but safari does not.

Myron
___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


Re: [Radiant] Caching issue

2009-11-30 Thread Anton Aylward
Myron Marston said the following on 11/30/2009 06:26 PM:
 Perhaps this ties in with my Last-Modified header question.

 
 Anton--I looked through the archives and couldn't find this question.  I'd
 be curious to read that thread if you can point me in the right direction.

Resent.

I looked at the W3 pages that described such things and their use,
and there are an awful lot of headers to play with ;-)  Do all
browsers implement all of them?  I'm sure one or other of them could
get the 'renew' effect you want, if and only if the browser pays
attention to it!!

 There are several extensions for Firefox that will let you view cache
 headers.  Web Developer and Firebug both come to mind.  For Firebug, clear
 your cache, enable Firebug, click the Net tab in the Firebug panel and
 load the offending page in Firefox.  You should see an entry in the Net
 panel with a Headers tab.
 
 
 Thanks for the suggestion.  I should have a been a bit more specific
 though...I know how to view the cache headers in safari and firefox, but I'm
 still trying to wrap my head around how these headers work (I just read up
 on them today for the first time), and I'm not sure what to try next.

You and me,'Bro, you and me!  That W3 stuff and all those headers is
heady stuff :-)


-- 
helicopter (n): 30,000 parts in tight orbit around a hydraulic fluid
leak, waiting for metal fatigue to set in.
___
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant