[typo] Re: calling controller and caching from a sweeper class
lists at matiaspelenur.com
Mon Jun 27 04:01:59 EDT 2005
Just wanted to post again before giving up on this...
Is there a way to call a controller action directly and have the paged cached?
See below for the whole story.
So far the only solutions proposed are doing a system(wget), but there must be a
better one... In any case even that option doesn't work; the reason I have this
problem is because I want to password-protect (via Basic auth) the web app, but
allow free access only to those feed .xml files. Because of the way auth goes
through Apache, and because I'm using FastCGI so everything goes through
dispatch.fcgi, I can only do what I want if I always have the physical cached files.
In any case, even without this convoluted scenario of mine, there must be a way
to do what I want... Imagine if some cached pages took a long time to generate;
you might want to force-refresh them when there's a change to the model?
Matias Pelenur wrote:
> [cross-posting to rails and typo lists]
> I'm tinkering with the code for typo, a rails-based blog engine.
> Typo has an XmlController with actions "rss" and "atom" which generate
> feed.xml files, and it uses a caches_page declaration to cache the files
> that get generated by those actions. It also has a Sweeper (Observer)
> class that expires those cached files when a blog post is created or
> The normal behavior is that the files get deleted when expire_cache is
> called, and then re-created the next time the XmlController action is
> Now, I'm trying to force the files to be re-cached immediately after the
> expire_cache call from the Sweeper class. However I could not find a way
> to do that successfully.
> I've tried several ways, including instantiating the controller in the
> sweeper and calling the actions directly (which doesn't work), and the
> closest I got was using render_component_as_string from the base
> ApplicationController. That sort-of works in that it at least it calls
> the proper XmlController action, but it has two problems: the pages
> aren't cached, and also the response type changes to xml (which confuses
> the browser since the response is a redirect).
> I wonder if anyone has a good idea of how the caching and stuff works,
> and what I can do to force certain controller actions to run and get
> cached as if they had been invoked by the browser, but instead invoking
> them from within an observer or controller.
> I'm using rails 0.12.1 on ruby 1.8.2.
> Thanks in advance for any help, please let me know if you need any more
More information about the Typo-list