python-3.xsqlitepython-lru-cache

Python lru_cache decorator with Sqlite database


I have a relatively simple py script that executes every minute as a Cronjob in Linux and performs a SELECT query on a Sqlite database using Sqlite3 library. Now, this ScriptE executes every minute to check whether there is a new record. SQL query is just a simple query that retrieves all records in the database whose dates match a datetime.data.today().

So, as you can imagine, these queries return data that is pretty much the same during the calls.

Usually, during each day, at the end of that day, there are about 150 records (rows).

Now, I wonder if it makes sense to use the lru_cachse decorator from functools. Most probably, I won't see any increase in performance since sql queries execute very fast, but still, I would like to know if there is any sense at all to using cache for this purpose.


Solution

  • lru_cachse is suitable to applying repetitive calculate function, as your description, the data is very few, you need to do nothing.if you really want ,maybe you should record latest primary key list in your cache, and you can rule out these keys in your next query