views:

34

answers:

3

I am trying to create a site in RoR and have enabled caching for some pages and actions. The related DB may not accessible every time and hence using the cache is very much required. Hence I cant wait for someone to actually visit the page, render it and then cache it. Instead I want whatever is cache-able to be cached manually, programatically. Is it actually possible or is it that caching is completely automatic in RoR?

A: 

Ref :- Link

class ProductsController < ActionController 
  caches_page :index  
  def index

  end
end 

set perform caching to true in your enviorment config/environments/development.rb

config.action_controller.perform_caching = true 
Salil
-1: see quote from the link you provided: "The first time anyone requests products/index, Rails will generate a file called index.html" but the author doesn't want to wait until someone visits the page, he wants it to be cached in advance.
neutrino
@neutrino: exactly. But is it possible?
Mahesh M
A: 

The lazy* solution would be to visit the page as part of your deployment process with lynx, or even curl. That would trigger the cache event from the outside, but at a time of your choosing.

(*) lazy in a good way, I hope.

Govan
:) But is the cache event so inaccessible from within?
Mahesh M
A: 

Check out this page_cache plugin. Seems like this is what you need.

neutrino
page-cache plugin is being used. But it doesnt give the whole control from within application. Rake has to be called by cron. Not exactly what I wanted but may be that is the only way.
Mahesh M