0

I am creating large session objects in my app. When I use cached_db backend, the response time gets significantly longer because the session objects are written to the DB before the response is returned to the user. Is there a way to save the sessions after the response is returned?

Note: This behavior doesn't happen when I use cache backend.

ahmohamed
  • 2,920
  • 20
  • 35
  • Why do you want to use large sessions objects? – dan-klasson Sep 24 '15 at 14:30
  • Session data stores objects that the user modifies with client-side requests. These objects are large (lists of) numpy arrays, and they are modified by calculations driven by a series of user requests. – ahmohamed Sep 24 '15 at 14:36
  • Why not just have the server return that data when they need it instead? – dan-klasson Sep 24 '15 at 14:51
  • If the server sent the data back to the user with every response, then again the user will upload the data for the next operation. With such large data, this repetitive upload/download is extremely inefficient. I'd rather store the object on the server, and have the user reference it in the request. – ahmohamed Sep 24 '15 at 15:08
  • Any way, I actually found a way to do that, by [subclassing HttpResponse](http://stackoverflow.com/a/4314182/3192855) and [session middleware](https://github.com/django/django/blob/master/django/contrib/sessions/middleware.py#L50). It is not very clean, but if it is the only way, so be it. – ahmohamed Sep 24 '15 at 15:10
  • Sessions are not stored on the server though. – dan-klasson Sep 24 '15 at 15:44
  • Could you please elaborate on what you meant by "have the server return the data when they need it"? – ahmohamed Sep 24 '15 at 15:46
  • Well, assuming you are updating the whole session when there is a change. You could update the part when there is a change. And that is mostly done through a REST API. Having the client request data when they need it. I.e for them to request small amounts of data when they are in need of it. – dan-klasson Sep 24 '15 at 15:49

0 Answers0