我是一个铁杆新手试图为我的应用程序实现缓存.我安装了memcached并在我的development.rb中配置它,如下所示:
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
Run Code Online (Sandbox Code Playgroud)
我有一个控制器ProductsController,它在登录时显示用户特定的产品.
class ProductsController < ApplicationController
caches_action :index, :layout => false
before_filter :require_user
def index
@user.products
end
end
The route for index action is: /products
Run Code Online (Sandbox Code Playgroud)
问题是,当我登录时
1)用户A第一次,rails命中我的控制器并缓存产品动作.
2)我注销并以用户B身份登录,它仍以用户A身份登录并显示用户A而非用户B的产品.它甚至没有打到我的控制器.
关键可能是路由,在我的memcached控制台中,我看到它是基于相同的密钥获取的.
20 get views/localhost:3000/products
20 sending key views/localhost:3000/products
Run Code Online (Sandbox Code Playgroud)
动作缓存不是我应该使用的吗?我如何缓存和显示用户特定的产品?
谢谢你的帮助.