Cache Aging Check Algorithm

My python script does some heavy computing. To improve performance, it caches the calculated data on disk, so the next time I run it, it does not waste time calculating the same. However, before retrieving data from the cache, you need to do some checking to make sure that the cache is not expired. This is the part that I'm stuck in.

My first idea was to compare the cache creation time and the python script modification time, and if the size is later (i.e. later) than the first, I would consider the cache obsolete, otherwise not. However, since the linux kernel does not store file creation time, I am stuck at this point.

A similar situation:
When the python interpreter creates .pyc files from .py files, it does something similar -> it creates a new .pyc file if I change my .py file after creating the .pyc file, otherwise it is not. How does it do this? I want to know the algorithm. Thanks.

+4
source share
2 answers

Just check the last time your cache file.

Even better, you really want to check in any case, because when you update your cache to store the new calculated value, you want to know when it was last done, and not when it was done the first time. :-)

+2
source

You may have a metadata file that will contain a list of all cached objects along with the time they were created

0
source

Source: https://habr.com/ru/post/1433338/


All Articles