Hi, I''ve been investigating various caching methods provided by Rail. I first looked at the hash_cache module and function. In testing it, I noticed it wasn''t actually caching anything. Then looking at the source code, I noticed that it attempted to hold its cache in a class variable - which won''t actually be saved from page request to page because of the way that rails works. Hash_cache seems to be a complete bogus, non-functional function which has been carried and documented for a while. Am I missing something? Anyway, my test functions (within a descendant of application_controller): def cacheTest i = params[:id] res = methodToCache_cache[i] print "value returned #{i}\n\n" render_text res end def methodToCache i print "\n\nmethod actually called #{i}\n\n" return "test text <%print #{i}%>" end hash_cache :methodToCache The log results: ............ method actually called 67 value returned 67 127.0.0.1 - - [01/Sep/2007:16:15:19 Pacific Daylight Time] "GET /posts/cacheTest /67 HTTP/1.1" 200 22 - -> /posts/cacheTest/67 method actually called 67 value returned 67 127.0.0.1 - - [01/Sep/2007:16:15:20 Pacific Daylight Time] "GET /posts/cacheTest /67 HTTP/1.1" 200 22 ===> Calling the function with the same values twice resulted in the being called twice, IE, not cached. Has anyone tested this or other caching functionality of rails? Joe -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I never used this, but I am wondering that maybe it only works in production environment instead of development and test envs? On Sep 2, 12:27 am, "H. joseph Solbrig" <rails-mailing-l...@andreas- s.net> wrote:> Hi, > > I''ve been investigating various caching methods provided by Rail. I > first looked at the hash_cache module and function. In testing it, I > noticed it wasn''t actually caching anything. Then looking at the source > code, I noticed that it attempted to hold its cache in a class variable > - which won''t actually be saved from page request to page because of the > way that rails works. > > Hash_cache seems to be a complete bogus, non-functional function which > has been carried and documented for a while. Am I missing something? > > Anyway, my test functions (within a descendant of > application_controller): > > def cacheTest > i = params[:id] > res = methodToCache_cache[i] > print "value returned #{i}\n\n" > render_text res > end > def methodToCache i > print "\n\nmethod actually called #{i}\n\n" > return "test text <%print #{i}%>" > end > hash_cache :methodToCache > > The log results: > ............ > method actually called 67 > > value returned 67 > > 127.0.0.1 - - [01/Sep/2007:16:15:19 Pacific Daylight Time] "GET > /posts/cacheTest > /67 HTTP/1.1" 200 22 > - -> /posts/cacheTest/67 > > method actually called 67 > > value returned 67 > > 127.0.0.1 - - [01/Sep/2007:16:15:20 Pacific Daylight Time] "GET > /posts/cacheTest > /67 HTTP/1.1" 200 22 > > ===> Calling the function with the same values twice resulted in the > being called twice, IE, not cached. > > Has anyone tested this or other caching functionality of rails? > > Joe > -- > Posted viahttp://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jack Zhan wrote:> I never used this, but I am wondering that maybe it only works in > production environment instead of development and test envs? > > On Sep 2, 12:27 am, "H. joseph Solbrig" <rails-mailing-l...@andreas-Definitely this is the problem. Classes are reloaded every request when in development. Besides, a hash-based cache would be an in-process cache only, and if you''re deploying like most people, you''re using multiple processes, so you could never share the cache. -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-03 06:45 UTC
Re: hash_cache a bogus function that never worked?
hash_cache is not intended as a response caching mechanism. Rails has a number of solutions for this such as page, action, and fragment caching. There is a nice peepcode video on caching in rails, btw, and a number of other resources available. In answer to the rails environment question, hash_cache doesn''t work in development for the reason stated: the classes are reloaded, wiping out the class variable holding the cache. Similarly, normal caching in rails is turned off in the development environment as well. Rein On Sep 2, 7:08 pm, Bryan Duxbury <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jack Zhan wrote: > > I never used this, but I am wondering that maybe it only works in > > production environment instead of development and test envs? > > > On Sep 2, 12:27 am, "H. joseph Solbrig" <rails-mailing-l...@andreas- > > Definitely this is the problem. Classes are reloaded every request when > in development. Besides, a hash-based cache would be an in-process cache > only, and if you''re deploying like most people, you''re using multiple > processes, so you could never share the cache. > -- > Posted viahttp://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
H. joseph Solbrig
2007-Sep-03 19:53 UTC
Re: hash_cache a bogus function that never worked?
Thank you all for information. Sorry if my original post came off as a bit hostile. It seems a little odd to me that development and production environments would have different configurations. The point of development IMHO is to test everything that will go into production, with assert and debugging added but nothing removed. But considering that it seem development and production are different, could someone point me to any documentation describing this or other differences? - On the subject of caching, I''m caching a lot of my page calculation but there some fields, spread through the page, that need to be calculated on-the-fly with page request. Thus neither caching a whole raw page nor caching a whole partial will work easily. Instead, I want to a page and then do some more calculations on it with each request. The crude functionality of hash_cache seemed suited for this. It there another way folks could suggest? Thanks again for all the useful advice so-far. Joe unknown wrote:> hash_cache is not intended as a response caching mechanism. Rails has > a number of solutions for this such as page, action, and fragment > caching. There is a nice peepcode video on caching in rails, btw, and > a number of other resources available. > > In answer to the rails environment question, hash_cache doesn''t work > in development for the reason stated: the classes are reloaded, wiping > out the class variable holding the cache. Similarly, normal caching in > rails is turned off in the development environment as well. > > Rein > > On Sep 2, 7:08 pm, Bryan Duxbury <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, 3 Sep 2007 21:53:10 +0200, H. joseph Solbrig wrote:> But considering that it seem development and > production are different, could someone point me to any documentation > describing this or other differences?~/myrailsapp $ cd config/environments ~/myrailsapp/config/environments $ diff development.rb production.rb :) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---