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

  • Home
  • SEARCH
  • 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 628763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:40:19+00:00 2026-05-13T19:40:19+00:00

I’m writing a chat feature (like the Faceboook.com one) for a Google App Engine

  • 0

I’m writing a chat feature (like the Faceboook.com one) for a Google App Engine site. I need a way to keep track of what users have new messages. I’m currently trying to use Memcache:

class Message():
    def __init__(self, from_user_key, message_text)
        self.from_user_key = from_user_key
        self.message_text = message_text

class NewMessages():
    def __init__(self):
        self.messages = []
    def add_message(self, message):
        self.messages.append(message)
    def get_messages(self):
        return self.messages
    def messages_sent(self):
        self.messages = [] #Clear all messages

def ChatUserManager():
    def load(user_key):
        manager = memcache.get("chat_user_%s" % user_key)
        if manager is not None:
            return manager
        else:
            manager = ChatUserManager(user_key)
            memcache.set("chat_user_%s" % user_key, manager)
            return manager
    def save(self):
        memcache.set("chat_user_%s" % user_key, self)
    def __init__(self, user_key):
        self.online = True
        self.new_messages = NewMessages()
        self.new_data = False
        self.user_key = user_key
    def recieve_message(self, message):
        self.new_data = True
        self.new_messages.add_message(Message(from_user_key, message_text))
    def send_message(self,  message):
        to_manager = ChatUserManager.load(message.from_user_key)
        to_manager.recieve_message(message)
    def client_receive_success(self):
        self.new_data = False
        self.new_messages.messages_sent()

This chat is user to user, like Facebook or an IM session, not group chat.

Each user will poll a url with ajax to get new messages addressed to them every x seconds. The chat manager will be loaded on that page (ChatUserManager.load(user_key)) and new messages will be checked for. When they are sent the manager will be told that the messages have been sent (manager.client_receive_success()), and then saved back to memcache (manager.save()).

When a user sends a message in the javascript client, it will send an ajax request to a url. The url will load the client’s UserChatManager and call .send_message(Message(to_user_key, message_string))).

I’m concerned about the practicality of this model. If everything is in memcache how will it be synchronized across different pages?

Is there a better way to do this?

I do admit that I’m not a python pro yet so the code might not be very pythonic, are there any best practices I’m missing?

  • 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-05-13T19:40:19+00:00Added an answer on May 13, 2026 at 7:40 pm

    The problem isn’t so much about how to share data between “pages” but how will the usability of the service will be impacted by using memcache.

    There are no guarantees associated with data persistence in memcache: one moment its there, the other it might not.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.