I have a simple service that does approximately the following:
- An HTTP client connects to the server
- The server writes the sessionID of the client and the timestamp to the database, and in most cases just returns an empty response
(The cases when it does do real work and return actual data are irrelevant to this question)
In order to return this response as soon as possible, I'd like to write the info to memcache in the request handler's body (because memcache is fast), and to spawn a separate thread where another function using SQLAlchemy will write it to the persistent storage. This way, I'll be able to return immediately after writing to memcache and spawning a thread, and the request handler will not have to wait until SQLAlchemy saves the info to the database.
Does this make sense? If yes, how should I implement it?