Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:44:23+00:00 2026-06-09T11:44:23+00:00

So, this problem is rather elaborate. I’ll try to explain as best I can.

  • 0

So, this problem is rather elaborate. I’ll try to explain as best I can. Any help would be extremely appreciated. Thanks in advance!

I’m building an application that uses tornadio2 + Memcached, and am finding some perplexing things when trying to pull from cache.

For starters, here is my broadcast_to_players() function:

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

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.

However, when I try to grab the same game from cache again, it says the secret_key = None

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

The game is being cached, but the player_list isn’t being updated in the Game model. Here are my Game and Player models:
http://pastebin.com/t66qgeeb – Game model
http://pastebin.com/7FjpeSLx – Player model

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:44:24+00:00Added an answer on June 9, 2026 at 11:44 am

    Ok. Let’s move point by point:

    1. Don’t put big objects in memcached – you will have high chance of
      miss.
    2. In this case – split keys. You must have one key for game, one key player list, and keys for each player in the game.
    3. Store player in memcache by key player_<g_id>_<key> – then you will be able to get player easily.

    Let’s put it all together:

    def broadcast_to_players(self, g_id, event, message, update_secret=False, dont_update_self=False):
        the_game = cache.get(g_id)
        player_list = cache.get('game_%s_players' % g_id) #Getting list of players ids
        for player_key in player_list:
            player = cache.get('game_%s_%s' % (g_id, player_key))
            if update_secret == True:
                secret = self.get_secret()
                message['k'] = secret
                player.secret_key = secret
                player.save() #We are storing secret in db, right?
                cache.set('game_secret_%s_%s' % (g_id, secret), player_key) #Making player availiable in game by secret
                cache.set('player_%s_secret' % (player_key, ), secret) #Making player secret available by player id
            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)
    
    def check_player(self, g_id, key):
        return cache.get('game_secret_%s_%s' % (g_id, key))
    

    It’s only idea, how you should think, when working with key/value storages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is very strange and I'm hoping someone can help me. For the
If *get_ii() returned heap memory, rather than stack memory, would this problem be eliminated?
Can anyone help me out of this problem, my javascript has an ajax GET
I am kind of really stuck with this problem. Any help will great. I
Apologies for the rather verbose and long-winded post, but this problem's been perplexing me
I've been having this rather frustrating problem, and having failed so many times, I'm
we're having this big problem with our application. It's a rather large application with
I occasionally get this problem, and generally work around it, but it's rather frustrating.
This problem crops up every now and then at work. Our build machine can
I am facing a rather odd problem right now. If you fellow this :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.