Django vars in ram

I am implementing a really lightweight web project that has only one page showing the data in a diagram. I use Django as a web server and d3.js as a charting scheme. As you can imagine, there are just a few simple time series that the Django server should respond to, so I was wondering if I could just save this variable in ram. My first test was positive, I had something like this in my views.py:

X = np.array([123,23,1,32,123,1])

@csrf_exempt
def getGraph(request):
    global X
    return HttpResponse(json.dumps(X))

Please note that it is Xupdated by another function from time to time, but all user access is read-only. Should I deal with

  • security problems by defining a global variable?
  • discrepancies in general?

I found a thread discussing global variables in Django, but in this case, the difficulty lies in handling multiple write capabilities.

To answer potential questions about why I don't want to store data in a database: all the data that I received in mine Xis already stored in a huge remote database, and this web application just needs to display the data.

+5
source share
1 answer

Storing it in a variable really has the effects of threads (as well as scalability - what if you have two Django servers running the same application?). The Django Community Council does not do this.

Django. getGraph @cache_page, . memcache, - * . - ().

, HTTP- (JSON), X. . X, JSON, JSON, X.

https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs/


1 " ",

+2

All Articles