Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 RubyonRails:如果是AJAX请求,如何将内容过期时间设置为15分钟_Ruby On Rails_Ajax_Browser Cache_Cache Control - Fatal编程技术网

Ruby on rails RubyonRails:如果是AJAX请求,如何将内容过期时间设置为15分钟

Ruby on rails RubyonRails:如果是AJAX请求,如何将内容过期时间设置为15分钟,ruby-on-rails,ajax,browser-cache,cache-control,Ruby On Rails,Ajax,Browser Cache,Cache Control,以下是检测AJAX请求并将过期时间设置为15分钟以便同一GET不需要任何网络流量的好方法吗 # in controller if request.xhr? response.headers['Expires'] = (Time.now + 15.minutes).httpdate response.headers['Cache-Control'] = '' # override any no-cache, must-revalidate end 更新:我发现了一个较短的备选方案,即

以下是检测AJAX请求并将过期时间设置为15分钟以便同一GET不需要任何网络流量的好方法吗

# in controller
if request.xhr?
  response.headers['Expires'] = (Time.now + 15.minutes).httpdate
  response.headers['Cache-Control'] = ''   # override any no-cache, must-revalidate
end
更新:我发现了一个较短的备选方案,即

但是,在此之后,标题变为:

Cache-Control: max-age=900, private
以前是

Expires: Tue, 13 Jul 2010 00:59:47 GMT

当它是早期版本时。但请注意,缓存控制是针对HTTP/1.1的,甚至在几年前,99%的浏览器都支持它,如《高性能网站手册》中所述。

好的,因为还没有答案,我将使用上面更新中的一个:

if request.xhr?
  expires_in(15.minutes)
end
我试过了,效果很好

if request.xhr?
  expires_in(15.minutes)
end