My python script does some heavy computation. To boost performance, it caches the computed data on the disk so that next time I'll run it, it doesn't waste time in computing the same thing. However, before extracting data from the cache, it needs to do some checking to make sure that the cache is not stale. This is the part where I am stuck.
My first idea was to compare the creation time of cache and modification time of python script and if the later is larger (ie more recent) than the former, I would consider the cache as stale, else not. However, since linux kernel does not store creation times of files, I am stuck at this point.
Similar situation:
When python interpreter creates .pyc files from .py files, it does something similar --> creates a new .pyc file if I'll modify my .py file after the .pyc file was created, else it does not. How does it do that? I wish to know the algorithm. Thank you.
Just check the last-modified time of your cache file instead.
Even better, that's what you really want to check in any case, because when you update your cache to store the new computed value, you want to know when that was done last, not when that was done the first time. :-)
Algorithm to check if cache is stale