Is there a builtin application hash, similar to the session hash? Except obviously at the application rather than just the user session level.
On Apr 7, 2005 4:14 PM, Steve V <ruby-ChEX1j9zMF7JbC0vcoRRxNBPR1lH4CV8@public.gmane.org> wrote:> Is there a builtin application hash, similar to the session hash? Except > obviously at the application rather than just the user session level.Any class level hash will do. Just bear in mind that if you run more than one process, you''ll need to use memcached or drb or something.> _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
> Any class level hash will do. Just bear in mind that if you run more > than one process, you''ll need to use memcached or drb or something.Something like $application = Hash.new() in environment.rb you mean? I''m a little confused though about the multi-process issue. Are you saying that if I''m running mod_ruby or FCGI, that the $application variable would be shared amongst each site that I have running this application? I thought that each site I would run in Apache would be in its own little sandbox. Is this not the case? Steve
> Something like $application = Hash.new() in environment.rb you mean?Nope, in ApplicationController: before_filter :set_defaults def set_defaults @application = Hash.new # set the hash end The @ makes it an instance variable. -Lucas http://rufy.com/
Steve, On 7.4.2005, at 08:10, Steve V wrote:>> Any class level hash will do. Just bear in mind that if you run more >> than one process, you''ll need to use memcached or drb or something. > > Something like $application = Hash.new() in environment.rb you mean?I think he means that the hash is stored as a class variable: class Someklass < AR::Base @@myhash = Hash.new end> > I''m a little confused though about the multi-process issue. Are you > saying > that if I''m running mod_ruby or FCGI, that the $application variable > would > be shared amongst each site that I have running this application?The issue is rather that if you run multiple fcgi processes (for a single site), they won''t share the value of that hash unless you use some external storage for it. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> > Something like $application = Hash.new() in environment.rb you mean? > > Nope, in ApplicationController: > > before_filter :set_defaults > > def set_defaults > @application = Hash.new > # set the hash > end > > The @ makes it an instance variable.Yes, but the purpose of having something at the application level is that it is not recreated with every request. Rather the collection would stay there for all requests. Steve
Then all you need to do is: if @application.nil? @application = Hash.new # set the hash end -Lucas http://www.rufy.com/ On Apr 6, 2005, at 10:39 PM, Steve V wrote:> >>> Something like $application = Hash.new() in environment.rb you mean? >> >> Nope, in ApplicationController: >> >> before_filter :set_defaults >> >> def set_defaults >> @application = Hash.new >> # set the hash >> end >> >> The @ makes it an instance variable. > > Yes, but the purpose of having something at the application level is > that it > is not recreated with every request. Rather the collection would stay > there > for all requests. > > Steve > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> Then all you need to do is: > > if @application.nil? > @application = Hash.new > # set the hash > endIt''s still at the instance level. Any changes made to it are not persisted(nor should they be in some instances). This variable should live and die with the application. The way you have shown will recreate and load the entire configuration on each request. Using the global seems like it will work just fine. Since I don''t know that much about how Ruby handles threading my only concern would be in regards to simultaneous access of collections and such. Steve
Ah, I see your point. Try class variables (@@). Globals are frowned upon. -Lucas http://www.rufy.com/ On Apr 6, 2005, at 11:26 PM, Steve V wrote:>> Then all you need to do is: >> >> if @application.nil? >> @application = Hash.new >> # set the hash >> end > > It''s still at the instance level. Any changes made to it are not > persisted(nor should they be in some instances). This variable should > live > and die with the application. The way you have shown will recreate and > load > the entire configuration on each request. > > Using the global seems like it will work just fine. Since I don''t know > that > much about how Ruby handles threading my only concern would be in > regards to > simultaneous access of collections and such. > > Steve > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I was trying to do something similar to this. Their really should be some way to easily expose a variable to the entire app at once. On Apr 7, 2005 2:33 AM, Lucas Carlson <rails-1eRuzFDw/cg@public.gmane.org> wrote:> Ah, I see your point. Try class variables (@@). Globals are frowned > upon. > > -Lucas > http://www.rufy.com/ > > On Apr 6, 2005, at 11:26 PM, Steve V wrote: > > >> Then all you need to do is: > >> > >> if @application.nil? > >> @application = Hash.new > >> # set the hash > >> end > > > > It''s still at the instance level. Any changes made to it are not > > persisted(nor should they be in some instances). This variable should > > live > > and die with the application. The way you have shown will recreate and > > load > > the entire configuration on each request. > > > > Using the global seems like it will work just fine. Since I don''t know > > that > > much about how Ruby handles threading my only concern would be in > > regards to > > simultaneous access of collections and such. > > > > Steve > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
and... I accidentally hit the send button. I was going to say that this would be useful for people who want to access global objects without having to store them in their own db table/field. On Apr 7, 2005 3:28 PM, Shalev NessAiver <snlists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was trying to do something similar to this. > > Their really should be some way to easily expose a variable to the > entire app at once. > > On Apr 7, 2005 2:33 AM, Lucas Carlson <rails-1eRuzFDw/cg@public.gmane.org> wrote: > > Ah, I see your point. Try class variables (@@). Globals are frowned > > upon. > > > > -Lucas > > http://www.rufy.com/ > > > > On Apr 6, 2005, at 11:26 PM, Steve V wrote: > > > > >> Then all you need to do is: > > >> > > >> if @application.nil? > > >> @application = Hash.new > > >> # set the hash > > >> end > > > > > > It''s still at the instance level. Any changes made to it are not > > > persisted(nor should they be in some instances). This variable should > > > live > > > and die with the application. The way you have shown will recreate and > > > load > > > the entire configuration on each request. > > > > > > Using the global seems like it will work just fine. Since I don''t know > > > that > > > much about how Ruby handles threading my only concern would be in > > > regards to > > > simultaneous access of collections and such. > > > > > > Steve > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On Apr 8, 2005 7:29 AM, Shalev NessAiver <snlists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> and... I accidentally hit the send button. > > I was going to say that this would be useful for people who want to > access global objects without having to store them in their own db > table/field. > > On Apr 7, 2005 3:28 PM, Shalev NessAiver <snlists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I was trying to do something similar to this. > > > > Their really should be some way to easily expose a variable to the > > entire app at once.There are issues with application-layer variables. Mostly it means the application is no longer shared-nothing, and handling more load is no longer just accomplished by adding more servers. You could create constants in the environment.rb or application.rb files, which would work, so long as you didn''t want to change the object. -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
Steve V wrote:> Is there a builtin application hash, similar to the session hash? Except > obviously at the application rather than just the user session level.You might be interested in the cache setup[1] used by Typo[2]. 1. http://typo.leetsoft.com/trac.cgi/file/trunk/app/models/simple_cache.rb 2. http://typo.leetsoft.com -- Lee