2014-07-23 17 views
0

如果我在Rails中使用Net :: HTTP加载我的网站的一部分,每次都会加载它,还是会将它与其余的页脚一起缓存?Do Net:HTTP调用/ Rails中的结果是否被缓存?

编辑:我的意思是脚本的其余部分目前缓存。 Net:HTTP结果会在页脚内部呈现,是否也会被缓存?我希望它每次都重新加载结果。

回答

0

不,Net::HTTP不会为您缓存任何内容。你将不得不实施缓存,或者使用一个能为你做的gem。但取决于你对Rails做了什么,Rails可以做到这一点 - 查看片段缓存。

0

看起来不像它,至少不会by default作为2011年也有在网段/ http.rb在具有下面的代码红宝石源文件注释:

# The following example performs a conditional GET using the 
    # If-Modified-Since header. If the files has not been modified since the 
    # time in the header a Not Modified response will be returned. See RFC 2616 
    # section 9.3 for further details. 
    # 
    uri = URI('http://example.com/cached_response') 
    file = File.stat 'cached_response' 

    req = Net::HTTP::Get.new(uri) 
    req['If-Modified-Since'] = file.mtime.rfc2822 

    res = Net::HTTP.start(uri.hostname, uri.port) {|http| 
     http.request(req) 
    } 

    open 'cached_response', 'w' do |io| 
     io.write res.body 
    end if res.is_a?(Net::HTTPSuccess) 

源文件的日期为7月9日。希望有所帮助。