I am using memcached.. and have the folllowing in my partial. <%CACHE.fetch ''all_categories'' do %> <ul> Category.all.each do |c| <li><%= c.name %> </li> end </ul> <%end %> When I check in the irb console the "all_categories" key does get populated. So..CACHE.fetch ''all_categories'' in irb does output the expected html list. But nothing gets outputted in my view. I am guessing this is some sort of syntax error, what am I doing wrong? -- 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.
Not sure what is "Category.all" in your "each" enumerator. Try this, assuming CACHE.featch ''all_categories'' is returning an array of sorts: <% CACHE.fetch(''all_categories'').each do |category| %> <ul> <li><%= category.name <http://c.name/> %> </li> </ul> <% end %> On Thu, Sep 16, 2010 at 11:02 PM, badnaam <asitkmishra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using memcached.. and have the folllowing in my partial. > > <%CACHE.fetch ''all_categories'' do %> > <ul> > Category.all.each do |c| > <li><%= c.name %> </li> > end > </ul> > <%end %> > > When I check in the irb console the "all_categories" key does get > populated. > So..CACHE.fetch ''all_categories'' in irb does output the expected html > list. > > But nothing gets outputted in my view. > > I am guessing this is some sort of syntax error, what am I doing wrong? > > -- > 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. > >-- Srikanth Shreenivas http://www.srikanthps.com @srikanthps -- 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.
On Sep 16, 6:32 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using memcached.. and have the folllowing in my partial. > > <%CACHE.fetch ''all_categories'' do %> > <ul> > Category.all.each do |c| > <li><%= c.name %> </li> > end > </ul> > <%end %> > > When I check in the irb console the "all_categories" key does get > populated. > So..CACHE.fetch ''all_categories'' in irb does output the expected html > list. > > But nothing gets outputted in my view. > > I am guessing this is some sort of syntax error, what am I doing wrong?In the case where the data is already in the cache the block is not yielded to, so nothing will be output. You could try changing it to a < %= but I''m not sure that mixes well with yielding to a block or the case when it is generated fresh data. Why not use cache_fragment ? Fred -- 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.
You are right.. changing it to the following throws a nasty syntax error. <%= Rails.cache.fetch "all_catgory" do %> <!-- generate html for categories --> <% end %> If I do <% cache(:key => ''all_category'') do %> <!-- generate html for categories --> <%end%> The it does work, BUT..somehow the page url is prepended to the cache key so essentially this fragment which is same across the app, misses for every new page load. [DEBUG 17-09-2010 12:06:37] Cached fragment hit: views/localhost/ categories/autos-motorcyles/vote_topics?key=all_category (0.4ms) [DEBUG 17-09-2010 12:06:37] Category Load (0.2ms) SELECT * FROM `categories` ORDER BY name ASC [DEBUG 17-09-2010 12:06:37] Cached fragment miss: views/localhost/ categories/autos-motorcyles/vote_topics?key=all_category (0.4ms) [DEBUG 17-09-2010 12:06:37] Rendered shared/_cat_nav_list (8.9ms) [DEBUG 17-09-2010 12:06:37] Cached fragment hit: views/localhost/ categories/autos-motorcyles/vote_topics?key=all_cities (0.3ms) [DEBUG 17-09-2010 12:06:37] User Load (0.1ms) SELECT distinct city FROM `users` [DEBUG 17-09-2010 12:06:37] Cached fragment miss: views/localhost/ categories/autos-motorcyles/vote_topics?key=all_cities (0.4ms) [DEBUG 17-09-2010 12:06:37] Rendered shared/_city_nav_list (4.7ms) Can someone please help! On Sep 16, 4:07 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 16, 6:32 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am using memcached.. and have the folllowing in my partial. > > > <%CACHE.fetch ''all_categories'' do %> > > <ul> > > Category.all.each do |c| > > <li><%= c.name %> </li> > > end > > </ul> > > <%end %> > > > When I check in the irb console the "all_categories" key does get > > populated. > > So..CACHE.fetch ''all_categories'' in irb does output the expected html > > list. > > > But nothing gets outputted in my view. > > > I am guessing this is some sort of syntax error, what am I doing wrong? > > In the case where the data is already in the cache the block is not > yielded to, so nothing will be output. You could try changing it to a < > %= but I''m not sure that mixes well with yielding to a block or the > case when it is generated fresh data. Why not use cache_fragment ? > > Fred-- 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.
On Sep 17, 8:09 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The it does work, BUT..somehow the page url is prepended to the cache > key so essentially this fragment which is same across the app, misses > for every new page load.cache fragments are keyed like that by default - you can override that by passing :controller/:action parameters to make up a path (this doesn''t need to be a real path in your application - it''s just how it builds the identifier for the cache entry Fred> > [DEBUG 17-09-2010 12:06:37] Cached fragment hit: views/localhost/ > categories/autos-motorcyles/vote_topics?key=all_category (0.4ms) > [DEBUG 17-09-2010 12:06:37] Category Load (0.2ms) SELECT * FROM > `categories` ORDER BY name ASC > [DEBUG 17-09-2010 12:06:37] Cached fragment miss: views/localhost/ > categories/autos-motorcyles/vote_topics?key=all_category (0.4ms) > [DEBUG 17-09-2010 12:06:37] Rendered shared/_cat_nav_list (8.9ms) > [DEBUG 17-09-2010 12:06:37] Cached fragment hit: views/localhost/ > categories/autos-motorcyles/vote_topics?key=all_cities (0.3ms) > [DEBUG 17-09-2010 12:06:37] User Load (0.1ms) SELECT distinct city > FROM `users` > [DEBUG 17-09-2010 12:06:37] Cached fragment miss: views/localhost/ > categories/autos-motorcyles/vote_topics?key=all_cities (0.4ms) > [DEBUG 17-09-2010 12:06:37] Rendered shared/_city_nav_list (4.7ms) > > Can someone please help! > > On Sep 16, 4:07 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Sep 16, 6:32 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am using memcached.. and have the folllowing in my partial. > > > > <%CACHE.fetch ''all_categories'' do %> > > > <ul> > > > Category.all.each do |c| > > > <li><%= c.name %> </li> > > > end > > > </ul> > > > <%end %> > > > > When I check in the irb console the "all_categories" key does get > > > populated. > > > So..CACHE.fetch ''all_categories'' in irb does output the expected html > > > list. > > > > But nothing gets outputted in my view. > > > > I am guessing this is some sort of syntax error, what am I doing wrong? > > > In the case where the data is already in the cache the block is not > > yielded to, so nothing will be output. You could try changing it to a < > > %= but I''m not sure that mixes well with yielding to a block or the > > case when it is generated fresh data. Why not use cache_fragment ? > > > Fred-- 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.