Ruby on Rails Tuesday, December 30, 2014


Thanks Colin for your reply. Can you please let me know how can user_id be included in caching key string? I have following implementation of caching as of now.

app/views/employee/index.html.erb

<% cache "employee_list "do %>
  List of all employees:
  <% Employee.all.each do |e| %>
    <%= link_to e.name, employee_url(e) %>
  <% end %>
<% end %>

app/sweepers/employee_sweeper.rb

class EmployeeSweeper < ActionController::Caching::Sweeper
  observe Employee
  def sweep(employee)
   expire_fragment("employee_list")
 end
alias_method :after_create, :sweep
  alias_method :after_update, :sweep
  alias_method :after_destroy,:sweep
end

Devise "current_user" is accessible in all the above files.

--
Regards,
Ankur

On Tue, Dec 23, 2014 at 7:19 PM, Colin Law <clanlaw@gmail.com> wrote:
On 23 December 2014 at 13:42, Ankur Kumar <specialankur@gmail.com> wrote:
>
> Hi,
>
> My app has devise authentication for every user. I integrated fragment
> caching for one of my views which is accessible only on sign-in.
>
> The cached page saved by one user is accessible by another user. How can I
> implement a unique key based caching so that cached pages are unique for
> every user?

Include the user id in the key string.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvnok5OsKHzcD2go8FhDtp7wpzLR%3DUiRj-V1P9nHdKTwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALSL1eO79u_7T%2BkA-_i2mRosRA97KANKQO5-JxNFvMCqX-uEiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment