Rails fragment caching with personalization -


my site has top navigation menu bar has infrequently changed contents , it's therefore candidate fragment caching. if user signed in, part of menu bar have user's name in it, , therefore personalised , can't cached.

i can either:

  1. fragment cache static part , serve personalised part separately. seems pretty easy.

  2. cache lot, possibly in memcached or cloudfront, keep user's name in session, , use javascript extract user's name session , personalise page @ client end.

what best option go with? preferably based on personal experience of similar situations.

try this:

  ##in user.rb cache user   after_save :invalidate_cache    def self.serialize_from_session(key, salt)     single_key = key.is_a?(array) ? key.first : key     rails.cache.fetch("user:#{single_key}")       user.where(:id => single_key).entries.first     end   end     def invalidate_cache     rails.cache.delete("user:#{id}")   end 

credit: rails devise: how (mem)cache devise's database requests user object?


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -