Monday, April 11, 2011

Store last created model's row in memory

I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB.

In general, all changes are stored in DB as history, but I want the recent change duplicated in memory.

So the problem is: i want one variable to be stored in memory instead of DB.

From stackoverflow
  • You can use the cache system:

    http://docs.djangoproject.com/en/dev/topics/cache/#topics-cache

  • Unfortunately I don't believe you can do this unless you only have one instance of Python running, in which case you can use a global variable. With most web implementations you have a threaded server so this would not work. You would have to do a fetch from the database to get the latest copy of the record.

    If this is a very high-usage situation, you may want to look into memcached (or similar) as a way of lowering the performance overhead of hitting the database for each request.

  • You'd either have to use a cache, or fetch the most recent change on each request (since you can't persist objects between requests in-memory).

    From what you describe, it sounds as if it's being hit fairly frequently, so the cache is probably the way to go.

  • Would something like memcached be suitable?

0 comments:

Post a Comment