I need to make a model for battles in my app that contains players, etc. I don''t want to save this to the DB as it doesn''t need to be stored that long (and a server reboot killing it isn''t really a problem). I don''t want to save it in sessions since it applies to more than one player (but I would like to associate a battle with a player has_one style) But, I''m not sure what my options really are here. Really I just want to store it in memory but I can''t see how I''d do that and have it shared between requests. Thanks for any suggestions :) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/14/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to make a model for battles in my app that contains players, etc. I > don''t want to save this to the DB as it doesn''t need to be stored that long > (and a server reboot killing it isn''t really a problem). I don''t want to > save it in sessions since it applies to more than one player (but I would > like to associate a battle with a player has_one style) > > But, I''m not sure what my options really are here. Really I just want to > store it in memory but I can''t see how I''d do that and have it shared > between requests. > > Thanks for any suggestions :)Perhaps a seperate thread / process / service?
On 9/14/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> But, I''m not sure what my options really are here. Really I just want to > store it in memory but I can''t see how I''d do that and have it shared > between requests.You might check out Madeleine [1], the persistance (or pervalance, in the decreed vernacular) layer behind Instiki. It stores *everyithing* to memory. HTH, Stephen [1] http://www.rubygarden.org/ruby?Madeleine
Josh Charles <josh.charles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:>> But, I''m not sure what my options really are here. Really I just want to >> store it in memory but I can''t see how I''d do that and have it shared >> between requests.You might look at Madeline (http://madeleine.sourceforge.net/), it''s an in-memory object store. I think Instiki is using it now. If I understand right, Instiki uses Madeline as a replacement for ActiveRecord, but still uses ActionPack for the controller and view. I''d assume there''s no problem mixing AR and Madeline based models.>From the controller''s point of view, a data object is just an object.There''s no hard ties to AR. -- Doug Alcorn - http://lathi.net/RubyOnRailsDeveloper doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
I have on occasion set up a simple Hash in environment.rb and assigned it to a constant (APP_SCOPE). So if you build a model that''s read-only you can put it there and it will be available to all requests--on that machine. I''ve done that for data sources that were too expensive to create every request, but also had no reason to be limited to a session, as you say. I struggled for a while to find an equivalent to the java servlet container''s ''App Scope'' before I realized that even in development mode resources allocated in the ''environment'' startup files persist in memory. If you need read-write access or access across machines, a separate threadsafe data structure or distributed service (dRB) seems best. Jonathan Broad On Sep 14, 2005, at 2:35 PM, Patrick McCafferty wrote:> I need to make a model for battles in my app that contains players, > etc. I don''t want to save this to the DB as it doesn''t need to be > stored that long (and a server reboot killing it isn''t really a > problem). I don''t want to save it in sessions since it applies to > more than one player (but I would like to associate a battle with a > player has_one style) > > But, I''m not sure what my options really are here. Really I just > want to store it in memory but I can''t see how I''d do that and have > it shared between requests. > > Thanks for any suggestions :) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Patrick McCafferty wrote:> I need to make a model for battles in my app that contains players, > etc. I don''t want to save this to the DB as it doesn''t need to be > stored that long (and a server reboot killing it isn''t really a > problem). I don''t want to save it in sessions since it applies to more > than one player (but I would like to associate a battle with a player > has_one style) > > But, I''m not sure what my options really are here. Really I just want > to store it in memory but I can''t see how I''d do that and have it > shared between requests. > > Thanks for any suggestions :) > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >Have you considered a memory table (in MySQL but I assume others have the same)? Then you could use ActiveRecord as-is. Jack Christensen _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hmm. That might not be a bad idea - I didn''t know such things existed :) Thanks (to you and all the other suggestions) On 9/15/05, Jack Christensen <jack-BsDU1ACF2Bglk5EcyZIkJQ@public.gmane.org> wrote:> > Patrick McCafferty wrote: > > I need to make a model for battles in my app that contains players, etc. I > don''t want to save this to the DB as it doesn''t need to be stored that long > (and a server reboot killing it isn''t really a problem). I don''t want to > save it in sessions since it applies to more than one player (but I would > like to associate a battle with a player has_one style) > > But, I''m not sure what my options really are here. Really I just want to > store it in memory but I can''t see how I''d do that and have it shared > between requests. > > Thanks for any suggestions :) > > ------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > Have you considered a memory table (in MySQL but I assume others have the > same)? Then you could use ActiveRecord as-is. > > Jack Christensen >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails