开发者

DJANGO persistant site wide memory

I am new to Django, and probably using it in a way thats not normal. That said, I would like to find a way to have site wide memory. To Explain.

I have a very simple setup where one compter will make posts to the site every few seconds. I want this data to be saved off somewhere. I want everyone who is viewing the webpage to see updates based on this data in near real time via some javascript.

So using the sample code below. Computer A would do a post to set_data and set data to "data set" Computer B,C,D,etc.... would then do a get to get_data and see "data set" Unfortunatly B,C,D just see ""

I have a feeling what i need is memcached, but I am on a hostgator shared server and cannot install that. In the meantime I am just writing them to files. This works but is really inneficient, and I am hopeing to serve a large user base.

Thanks for any help.

#view.py
data=""

def set_data(request):
    data = request.POST['data']
    return HttpResponse("");
开发者_运维问答
def get_data(request):
    return HttpResponse(data);


memcached is lossy, hence doesn't fulfil "persistent".

Files are fine, but switch to accessing them via mmap.


Persistent storage is also called database (although for some cases Django's cache backend might work as well). Don't ever try to use global variables in web development.

Whether you should use a Django model or the cache backend really depends on your use case, but you just described a contrived example (or does your web app consist of a getter and a setter?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜