Why not using etag/last-modified at and rack-cache? It's a very simple and elegant solution and straightforward to implement. If your app has a lot of traffic, you might want to swap rack cache with varnish to handle the HTTP caching.
- Matt On Thu, Dec 31, 2009 at 1:28 PM, David <[email protected]> wrote: > Hi all, any idea why this is happening to me? > > I've got a controller action that responds to both html and json > requests. Everything works fine. I'm trying to introduce page caching > into the mix and the json requests are being cached as .html. The > actual content of the cache is the json representation. > > From the log... > > Processing HomeController#index to json (for 127.0.0.1 at 2009-12-31 > 10:11:00) [GET] > Parameters: {"app_name"=>"coatable"} > SQL (0.1ms) SET NAMES 'utf8' > SQL (0.1ms) SET SQL_AUTO_IS_NULL=0 > Product Columns (536.1ms) SHOW FIELDS FROM `products` > Product Load (0.6ms) SELECT * FROM `products` WHERE > (`products`.`short_name` = 'coatable') LIMIT 1 > Cached page: /coatable.html (3.4ms) > Completed in 550ms (View: 0, DB: 537) | 200 OK [http://uhhuhyeah.local/ > coatable?format=json <http://uhhuhyeah.local/%0Acoatable?format=json>] > > And like I said, it's saving the json, but as an html file. > > For reference this is on Rails 2.2.2 and I *do* want to be able to > cache both the json and html versions. > Controller is something like > > def index > @app = Product.find_by_short_name(params[:id]) > responds_to do |format| > format.html {} > format.json { :render :json => @app } > end > end > > Thanks and good luck with the hangovers tomorrow. > > David > > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
