Heroku上的Ruby应用程序 - 为什么我的caches_action不能刷新?

时间:2012-10-17 18:18:10

标签: ruby-on-rails ruby heroku

我在Heroku上运行了一个RoR应用程序。在我的控制器中,我运行了简单的caches_action语句,例如:

caches_action :index, :expires_in => 5.minutes

def index 
    @articles = Article.main.paginate(:page => params[:page], :per_page => 10)
    ....
end

在文章模型中,使用范围语句(例如:

)根据发布的日期检索项目
scope :before, lambda{|timenow| {:conditions => ["time <= ?", timenow]}}
scope :published, where(:published => true).order("time DESC")
scope :main, before(Time.now).published

即使我将caches_action设置为5分钟,我仍然必须进入并手动清除今天文章的缓存,以显示在列表的顶部,在它们应该上线几个小时之后。 Heroku或Rails中是否存在全局缓存设置我在某处丢失了?

更多信息:

今天,当一篇新文章没有出现时,我尝试进入控制台并输入:

Rails.cache.clear

这没有效果。然后我尝试使用与索引控制器相同的ActiveRecord请求:

Article.main

...它返回了正确的文章,包括未在网站上显示的文章。

只有重新启动服务器才能重置缓存并显示文章。

1 个答案:

答案 0 :(得分:0)

我刚刚在heroku上创建了一个使用动作缓存的Rails项目。它适当地缓存请求15秒,然后刷新缓存。

你有没有可能不使用dalli宝石?

heroku addon:

heroku addons:add memcache:5mb

代码:

配置/ application.rb中

config.cache_store = :dalli_store

app / controllers / home_controller.rb

class HomeController < ApplicationController

  caches_action :index, :expires_in => 15.seconds
  def index
    @timestamp = Time.now
  end
end

应用程序/视图/家/ index.html.erb

<h1>hi!</h1>
I was generated at <%= @timestamp %>.
相关问题