Hi, I''m working on a website that has a very slow loading frontpage. I wanted to start by caching certain elements that have high load. For example, it loads the last 50 comments, along with the corresponding usernames, avatars and more. So I cached that fragment and created a sweeper that observes Comment and expires after every create or destroy action. However, I have two problems: - Every comment has a timestamp that gets displayed like "1 minute ago". When the fragment displaying the last 50 comments is cached, this timestamp gets cached as well. That means that even after 15 minutes, it still says "1 minute ago" until another comment is posted. Is there any way to take that bit out of the cached fragment so that it gets updated? Caching these comments saves us about 150 milliseconds, so we really do want to cache it! - When expiring a cached fragment, it sends along the subdomain. This means that when I create a comment at www.domain.com/comment/create, it will expire the cache for www.domain.com, but not for domain.com. I don''t want it to store two different cached fragments for www and non- www, as they''re exactly the same. I also want both the www and non-www page to expire. Should I do something like cache(:action => ''...'', :subdomain => false, :action_suffix => ''...'') and do the same for the expire_fragment part? Or is there a better solution? Thank you! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> - When expiring a cached fragment, it sends along the subdomain. This > means that when I create a comment atwww.domain.com/comment/create, > it will expire the cache forwww.domain.com, but not for domain.com. I > don''t want it to store two different cached fragments for www and non- > www, as they''re exactly the same. I also want both the www and non-www > page to expire. Should I do something like cache(:action => > ''...'', :subdomain => false, :action_suffix => ''...'') and do the same > for the expire_fragment part? Or is there a better solution?Sorry. The above doesn''t work! Even with :subdomain => false present, it will look for the www-version. Is there another way? Or should I start redirecting all www-requests to domain.com? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Agustin Nicolas Viñao Laseras
2009-Dec-16 23:47 UTC
Re: Re: Caching comments: timestamps and subdomains
With the first problem, you can do something like this: In the coment render the datetime when they create, like this: *user1 make a coment 2009-12-16 20:44* and with jquery (if you use jquery) you can transform the datetime to "time ago" format with this library: http://timeago.yarp.com/ Like this the fragment is cached and with javascript make the change. See the library timeago for the datetime format. _______________________ Agustin Viñao www.agustinvinao.com.ar agustinvinao (Skype) On Wed, Dec 16, 2009 at 7:47 PM, jhaagmans <jaap.haagmans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > - When expiring a cached fragment, it sends along the subdomain. This > > means that when I create a comment atwww.domain.com/comment/create, > > it will expire the cache forwww.domain.com, but not for domain.com. I > > don''t want it to store two different cached fragments for www and non- > > www, as they''re exactly the same. I also want both the www and non-www > > page to expire. Should I do something like cache(:action => > > ''...'', :subdomain => false, :action_suffix => ''...'') and do the same > > for the expire_fragment part? Or is there a better solution? > > Sorry. The above doesn''t work! Even with :subdomain => false present, > it will look for the www-version. Is there another way? Or should I > start redirecting all www-requests to domain.com? > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes, I''ve thought about that. Thanks for pointing me to that library. There''s no Rails way around it though? Thanks again :) On Dec 17, 12:47 am, Agustin Nicolas Viñao Laseras <agustinvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> With the first problem, you can do something like this: > > In the coment render the datetime when they create, like this: > > *user1 make a coment 2009-12-16 20:44* > > and with jquery (if you use jquery) you can transform the datetime to "time > ago" format with this library: > > http://timeago.yarp.com/ > > Like this the fragment is cached and with javascript make the change. > > See the library timeago for the datetime format.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> - When expiring a cached fragment, it sends along the subdomain. This > means that when I create a comment atwww.domain.com/comment/create, > it will expire the cache forwww.domain.com, but not for domain.com. I > don''t want it to store two different cached fragments for www and non- > www, as they''re exactly the same. I also want both the www and non-www > page to expire. Should I do something like cache(:action => > ''...'', :subdomain => false, :action_suffix => ''...'') and do the same > for the expire_fragment part? Or is there a better solution?I have another remark about this: I can''t fully disregard subdomains, as we actually use them for our users. If you go to username.domain.com/ you''ll call another controller than with www.domain.com. If I disregard the subdomain however, it will store both the fragments in /views/domain.com/?action_suffix=something. That won''t work. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Is there a way to explicitly say where to cache a fragment in the memory (e.g. cache(''/home/index/feed'') do .. end ) and expire it the same way (e.g. expire_fragment(''/home/index/feed'') ) ? On 17 dec, 11:47, jhaagmans <jaap.haagm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > - When expiring a cached fragment, it sends along the subdomain. This > > means that when I create a comment atwww.domain.com/comment/create, > > it will expire the cache forwww.domain.com, but not for domain.com. I > > don''t want it to store two different cached fragments for www and non- > > www, as they''re exactly the same. I also want both the www and non-www > > page to expire. Should I do something like cache(:action => > > ''...'', :subdomain => false, :action_suffix => ''...'') and do the same > > for the expire_fragment part? Or is there a better solution? > > I have another remark about this: I can''t fully disregard subdomains, > as we actually use them for our users. If you go to > username.domain.com/ you''ll call another controller than withwww.domain.com. > If I disregard the subdomain however, it will store both the fragments > in /views/domain.com/?action_suffix=something. That won''t work.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.