我是一个尝试为我的应用程序实现缓存的 Rails 新手。我安装了 memcached 并将其配置在我的 development.rb 中,如下所示:
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
我有一个控制器 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
问题是当我登录时
1) 用户 A 第一次,rails 击中我的控制器并缓存产品操作。
2)我以用户 B 的身份注销并登录,它仍然以用户 A 的身份登录,并显示用户 A 而不是用户 B 的产品。它甚至没有击中我的控制器。
关键可能是路由,在我的 memcached 控制台中,我看到它是基于相同的键获取的。
20 get views/localhost:3000/products
20 sending key views/localhost:3000/products
动作缓存不是我应该使用的吗?我将如何缓存和显示用户特定的产品?
谢谢你的帮助。