我有一個來自用戶的事件的動態反饋,當前用戶正在跟蹤這些事件,這些partials都是memcached,但我也想爲它自己做這件事。我擔心的是,如果我使用memcache,它會根據第一次寫入緩存而不是爲每個唯一用戶動態顯示每個用戶的相同內容。Memcached動態提要?
我該如何memcache飼料和@追加?如果當前用戶關注其他用戶,我該如何更新它?我假設我不能只用<%緩存包起來「喂」辦%>
注意:在使用Memcached和達利
<% @following = current_user.following.collect {|f| f["id"]} %>
<div class='content'>
<% unless Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", Time.now, Time.now.strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }.count == 0 %>
<div class='date_bar_container'><div class='date_bar'>Today</div></div>
<div class='content_wrapper'>
<%= render :partial => 'events/event', :collection => Event.where(:id => Rsvp.where(:event_id => Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", Time.now.strftime('%Y-%m-%d 00:00:00.000000'), Time.now.strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }).select("DISTINCT event_id").collect(&:event_id)).order('start_time asc')%>
</div>
<% end %>
<% unless Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", (Time.now + 1.day).strftime('%Y-%m-%d 00:00:00.000000'), (Time.now + 1.day).strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }.count == 0%>
<div class='date_bar_container'><div class='date_bar'>Tomorrow</div></div>
<div class='content_wrapper'>
<%= render :partial => 'events/event', :collection => Event.where(:id => Rsvp.where(:event_id => Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", (Time.now + 1.day).strftime('%Y-%m-%d 00:00:00.000000'), (Time.now + 1.day).strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }).select("DISTINCT event_id").collect(&:event_id)).order('start_time asc')%>
</div>
<% end %>
<% (2..15).each do |f| %>
<% unless Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", (Time.now + f.day).strftime('%Y-%m-%d 00:00:00.000000'), (Time.now + f.day).strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }.count == 0 %>
<div class='date_bar_container'><div class='date_bar'><%= dayofweek((Time.now + f.day).wday) %>, <%= month((Time.now + f.day).month) %> <%= (Time.now + f.day).day %>, 2012</div></div>
<div class='content_wrapper'>
<%= render :partial => 'events/event', :collection => Event.where(:id => Rsvp.where(:event_id => Rsvp.where(:voter_id => @following, :status => 'going').where("start_time > ? AND start_time < ?", (Time.now + f.day).strftime('%Y-%m-%d 00:00:00.000000'), (Time.now + f.day).strftime('%Y-%m-%d 23:59:59.000000')).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }).select("DISTINCT event_id").collect(&:event_id)).order('start_time asc')%>
</div>
<% end %>
<% end %>
</div>
而不是使用'「用戶_#{ user.id} _#{user.updated_at.to_i}「''你可以使用內建的'cache_key'方法。 http://apidock.com/rails/ActiveRecord/Base/cache_key請參閱頁面上的第三個示例。 – James
當然,已經忘記了那一個 –