Pratik Khadloya
Pratik Khadloya

Reputation: 12869

rails2 memcache expires_in problem

I have a strange problem with a Rails 2.3.4 application. The expires_in time is set to 10 seconds after each hour. But memcache seems to remember the value even after a cache flush.

caches_action :deals, :expires_in => (3600 - Time.now.to_i % 3600) + 10,
  :cache_path => Proc.new { |controller| "blah" }

Memcache output:

<8 new client connection  
<8 get mynamespace:views/show  
>8 END  
<8 set mynamespace:views/show 0 1457 20499  
>8 STORED  
<9 new client connection  
<9 flush_all
>9 OK  
<9 connection closed.  
<8 get mynamespace:views/show  
>8 END  
<8 set mynamespace:views/show 0 1457 20499  
>8 STORED  

Upvotes: 0

Views: 509

Answers (2)

Harry Wood
Harry Wood

Reputation: 2351

Make sure you are actually using memcached, and not the rails default cache mechanism. You should have something like this in your environment.rb :

config.cache_store = :mem_cache_store

I had a similar problem while trying to get caching working with :expires_in I didn't realise that the above was needed. Without it rails defaults to using a FileStore, or a MemoryStore, both of which will happily sit there caching, but ignoring the :expires_in option.

Thanks to this article on memcached basics by Rob Anderton for helping me figure this out in the end

Upvotes: 1

James
James

Reputation: 4807

Try putting your expires_in value inside a proc.

edit: I forgot to mention calling the proc with .call at the end.

Upvotes: 1

Related Questions