Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango memcached inconsistency
    text
    copied!<p>So, this problem is rather elaborate. I'll try to explain as best I can. Any help would be extremely appreciated. Thanks in advance! </p> <p>I'm building an application that uses tornadio2 + Memcached, and am finding some perplexing things when trying to pull from cache. </p> <p>For starters, here is my broadcast_to_players() function:</p> <pre><code>def broadcast_to_players(self, g_id, event, message, update_secret=False, dont_update_self=False): the_game = cache.get(g_id) for player in the_game.player_list: if update_secret == True: secret = self.get_secret() message['k'] = secret player.secret_key = secret if dont_update_self == True: if not self.session_id == player.session_id: single_session = self.session.server._sessions.get(player.session_id) single_session.conn.emit(event, message) else: single_session = self.session.server._sessions.get(player.session_id) single_session.conn.emit(event, message) cache.set(g_id, the_game) ## FOR TESTING PURPOSES ## if update_secret == True: other_game = cache.get(g_id) for player in other_game.player_list: print "player.secret_key in broadcast_to_players = %s" % player.secret_key </code></pre> <p>As you can see, it grabs the_game from cache, does stuff to it, modifies a message, updates the players in my player_list, and sends the message. Then, it sets the game in cache. Afterward, (for testing purposes) I grab it again and test to see if the secret_key values of each player made it in the cache. And they do. </p> <p>However, when I try to grab the same game from cache again, it says the secret_key = None</p> <pre><code>def check_player(self, g_id, key): the_game = cache.get(g_id) #I'm able to the_player = None for player in the_game.player_list: if player.secret_key == key: the_player = player return the_player </code></pre> <p>The game is being cached, but the player_list isn't being updated in the Game model. Here are my Game and Player models:<br> <a href="http://pastebin.com/t66qgeeb" rel="nofollow">http://pastebin.com/t66qgeeb</a> - Game model<br> <a href="http://pastebin.com/7FjpeSLx" rel="nofollow">http://pastebin.com/7FjpeSLx</a> - Player model </p> <p>As you can see, the Player model has a many-to-many relationship to Game, through User. Also, I have many non-persisting variables (for the game being played) that I keep in my Django model classes. My guess is it might be something to do with the fact that I'm grabbing all the players associated with my game, putting them in player_list, and then trying to update them? And memcached doesn't do that deep of a copy? I don't know, and I've been racking my brain trying to figure it out. Any help at all would be much appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload