Kieran Hayes
Kieran Hayes

Reputation: 641

Memcached stores data but Rails is not using it

environment.rb:

config.cache_store = :mem_cache_store, '127.0.0.1', { :namespace => RAILS_ENV.to_s }

development.rb:

config.action_controller.perform_caching  = true

This is the memcached output when I call the url.

get development:views/127.0.0.1:3000/aktionen.xml sending key development:views/127.0.0.1:3000/aktionen.xml END set development:views/127.0.0.1:3000/aktionen.xml 0 60 3 STORED

Controller

caches_action :index, :expires_in => 5.seconds, :layout => false, :format => :xml

Info

cache_pages produces no memcached activity at all. Rails writes aktionen.xml to the public folder, also ignoring expires_in and format parameters. Calling 127.0.0.1:3000/aktionen creates a aktionen.html file

Upvotes: 0

Views: 634

Answers (2)

Kenny
Kenny

Reputation: 794

Have you tried upping the expiry to something greater than 5 seconds, just to make sure the data hasn't expired before you can test for its existence?

Upvotes: 0

Vlad Zloteanu
Vlad Zloteanu

Reputation: 8512

Rails (as of 2.1) provides different stores for the cached data created by action and fragment caches. Page caches are always stored on disk.

Action caching is VERY similar to page caching, the only difference is that the request for the page will always hit your rails server and your filters will always run. To setup action caching our controller might look like this:

class BlogController < ApplicationController
  layout 'base'
  before_filter :authenticate  # <--- Check out my authentication
  caches_action :list, :show

More info here: http://railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2

Upvotes: 3

Related Questions