What you want and what you need are too often not the same thing!When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.(Quote by me 15th July 2009)

Re: app.get in controller or model?

ok, I auume you are asking how to re cach a page after it expires?I think that would be bad practice. There are many reasons why a cache could be expired and this could be triggered a number of times in a perceived cycle of events causing additional unnecessary load on your server.There is only one reason why you would want to do this, which is that it takes a long time to gather the data to load the page which implies you should be concentrating on speeding up the data retrieval rather than trying to re-cache.

Perhaps a better, more scaleable approah would be to create a table view to represent the data you are needing or fake a table view by using json. If after the cache is swept you store the data in a json file you could then load the page from the json rather than directly from the database you would find a massive improvement in performance without needing to re-cache.

Those are better alternatives but neither answers your question. If you really really want to do this then the best approach would be to

Create a rake task that would use curl to visit whatever paths you need to re-cache then call that rake task from your sweeper.A rake task has the benefit of being able to be called from wiothing a model or controller.

ALWAYS work harder to speed up the data retrieval in the first place! In addition to the table views and json approach mentioned above you should take a look at your table indexing and improving query performance.

What you want and what you need are too often not the same thing!When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.(Quote by me 15th July 2009)

Background tasks - There are many options for running background tasks in rails most of which are complete overkill for this specific case. The simplest option is to just fork the rake task into a new process when you call it.

What you want and what you need are too often not the same thing!When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.(Quote by me 15th July 2009)