Search code examples
ruby-on-railsmemcachedruby-on-rails-2

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  

Solution

  • Try putting your expires_in value inside a proc.

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