In Ruby on Rails how can I persist objects in memory between sessions -


I'm trying to make something (eventually a gem, but now an application) that works as follows.

For example, DB records are dog breeds. For each dog there is a dog parent class and a child is not known to real breeds till runtime.

When the server starts it will load the record with DB and will start the examples of classes based on the records, e.g. I can have two beagles and poodles when somebody comes to the server, they may want to use one of those dog instances.

Why not just make an example of flying? In my case "dogs" are basically classes that keep an algorithm and data. There is no change in the algorithm, the data changes (in the order of the day), but the execution of algorithm, which uses data and some dynamic data such as timestamp, will be transported multiple times.

It would be silly to make an example of an object re-creating and requesting only to load the data at the next request (not to change the status of requests). When I could use the same object again, I would create and destroy many objects in each other.

It is not understandable to keep it in session, because someone should want a dog; its session has beagal information; It is irrelevant (and not the scale).

How do I keep these items in memory? I basically want a lookup table to capture the examples. In Java, I will create a singleton with some type of hashp or array which sits in memory. In Rail, I tried this by making a singleton class in Lib folder. I think - I can not be considered this right - the example (the fact that this is a singleton controversial) is being lost when the session disappears.

The closest answer I found is basically everything in class areas and methods in some way that does not seem right.

TIA!

Apart from this: I have come from Java. In Java, I will only create an object that sits on a pile or perhaps a JNDI tree and as it came in HTTP requests, they will be handled by a servlet or EJB or some copy request item which could again reach the object continuously. . I can not get equivalent in the train.

Your example may be confused in its simplicity. I believe that your objects are quite complex and your benchmarking shows that it is not appropriate to do them on each request.

In production mode, classes are not loaded between requests, but there are examples of those classes, so using class members of the class I think that I have a way to go. Just use it to store your instances.

  class ObjectCache @@ objects = {: beagle = & gt; Beagle.New, Pedal = & gt; Poodle.new} def lookup key @@ objects [key.to_sym] and end  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -