开发者

rails2 memcache expires_in problem

开发者 https://www.devze.com 2023-04-09 17:27 出处:网络
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.

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  


Try putting your expires_in value inside a proc.

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号