Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails缓存问题?_Ruby On Rails_Ruby On Rails 3_Caching - Fatal编程技术网

Ruby on rails Rails缓存问题?

Ruby on rails Rails缓存问题?,ruby-on-rails,ruby-on-rails-3,caching,Ruby On Rails,Ruby On Rails 3,Caching,我有一个运行良好的rails博客应用程序。。然而,我对缓存做了一些实验,尽管已经恢复到以前的版本,但这里仍然存在一些问题 似乎所有页面都在缓存中或类似的地方(我已经清理了浏览器缓存),因为服务器日志没有显示任何访问数据库的信息 关于如何解决这个问题有什么线索吗? 谢谢 问题可能是您使用的页面缓存如下: class ProductsController caches_page :index def index @products = Product.all end end 实

我有一个运行良好的rails博客应用程序。。然而,我对缓存做了一些实验,尽管已经恢复到以前的版本,但这里仍然存在一些问题

似乎所有页面都在缓存中或类似的地方(我已经清理了浏览器缓存),因为服务器日志没有显示任何访问数据库的信息

关于如何解决这个问题有什么线索吗?
谢谢

问题可能是您使用的页面缓存如下:

class ProductsController
  caches_page :index
  def index
    @products = Product.all
  end
end
实际上,这会在/public目录中创建一个名为products.html的文件,因此该文件甚至不会触及Rails堆栈,而是呈现出来。清除浏览器缓存并不能解决问题,因为文件存储在服务器上。有两种方法使此缓存过期

第一种方法是创建一个清除缓存的操作,然后在需要清除缓存时调用该操作:

class ProductsController
  def clear
    expire_page :action => :index
  end
end
第二种方法是从命令行(bash)中删除.html文件:

因此,页面缓存令人困惑。很难判断页面何时被实际缓存以及存储在何处

注意:如果您没有使用页面缓存,则可以使用以下命令清除整个memcached cahce或内存缓存:

Rails.cache.clear

文件存储在公共目录中,这就是问题所在。非常感谢!
Rails.cache.clear