作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 post_index 操作中,我生成了不同类型的“@posts”,例如..
def index
case params[:listing_type]
when "all"
@posts = get_all_post_from_memcached
when "most_popular"
@posts = get_all_most_popular_from_memcached
respond_to do |format|
format.html
format.js #for ajax reqeusts
format.xml #for rss etc
end
end
end
##updated
def index
case params[:listing_type]
when "all"
#the key here is teh same key I used for memcached
if stale?(:etag => 'all_posts_key')
@posts = get_all_post_from_memcached
else
head :not_modified and return
end
when "most_popular"
if stale?(:etag => 'most_popular_key')
@posts = get_all_most_popular_from_memcached
else
head :notified and return
end
respond_to do |format|
format.html
format.js #for ajax reqeusts
format.xml #for rss etc
end
end
end
fresh_when
需要一个
etag
, 如果不同类型的渲染没有区别就使用它(在我的情况下,渲染是基于 html 或 ajax 不同的)
stale?
还需要一个
etag
并围绕 response_to 块。
etag
将根据不同的列表类型而有所不同。但似乎没有太多的灵活性
fresh_when
或
stale?
可以在这里使用吗?
respond_to
堵塞?
最佳答案
如果您有像 show 方法中那样的特殊响应处理,那么使用 stale? helper 。如果你没有像 edit 方法那样的特殊响应处理并使用默认渲染机制(即,你没有使用 response_to 或自己调用渲染),那么使用 fresh_when。
关于ruby-on-rails - rails fresh_when/stale?用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3744090/
在我的 post_index 操作中,我生成了不同类型的“@posts”,例如.. def index case params[:listing_type] when "all"
我看到很多这样的例子: def show @article = Article.find(params[:id]) fresh_when(@article) end 然而,该页面还包含有关登录
为什么以下(在开发模式下)错误地返回“304 未修改”- 在开发模式下运行时,Rails 中不应默认禁用此类功能? 我的 Controller 看起来像这样: class WidgetControll
我是一名优秀的程序员,十分优秀!