mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 563 forks source link

Caching query results #1019

Closed pljspahn closed 2 years ago

pljspahn commented 2 years ago

This could be either a feature request or a simple question. I didn't see any explicit documentation on this, so I'm assuming it's a feature request.

I am connecting to an obscure database with an obscure driver (Eloquence DB with SQL/R driver, both from Marxmeier software). This connects to a production DB that houses data for a retail POS/ERP type application.

The database has tables such as "product" and "customer" where the data might change but seldom does. I fetch this data with simple select statements and (as of now) do not need to commit any updates, I'm simply reading the data for display on a web application that will be public facing.

As this data will be public facing, I'd rather not have every request hit the database and would prefer to return cached values if they exist. This is primarily for performance reasons, as the server is hosted on-site and the internet connection is not particularly capable of handling thousands of users since the location is rural and options for internet here are limited.

I assume I will have to implement my own caching system here, and there's plenty of ways to handle that myself (ie saving the query results to a dedicated DB). But I'm wondering if there is already something included with pyodbc that will help. Are query results cached in any way? I see from another issue that you've mentioned that prepared statements will get cached, but not the result, is that correct?

v-chojas commented 2 years ago

You're right that this is not a functionality of pyODBC. Since resultsets can be very large in general, this is something up to you to implement carefully.