This blog post shows how to create a cursor class for MySQL Connector/Python which will allow you to cache queries. It will hold the query itself and the result in a global variable.
Note: this is a proof of concept and is only meant as a demonstration on how to extend MySQL Connector/Python.
Why query caching?
You are doing lots of queries that have the same result. It would be expensive to always run the same exact query. MySQL has already a query cache, and there is also memcached. But you like MySQL Connector/Python so much you’d like to do it yourself.
A cursor caching queries and their result
To demonstrate a simple implementation of a query cache, we inherit …
[Read more]