Jul-18-2021, 10:52 AM
Very cool Larz60+!
That looks to be very useful. I didn't even think about cacheing. I'm going to add that to my notes- thank you for the tip and explaining it.
That looks to be very useful. I didn't even think about cacheing. I'm going to add that to my notes- thank you for the tip and explaining it.
(Jul-18-2021, 08:21 AM)Larz60+ Wrote: I usually cache the files when in initial development phase, but then remove it prior to releasing the code, unless the data is quite static.
It's ok to leave cacheing in place if you check the files age, a simple method can do this:
def determine_file_age(self, filename): last_mod_time = filename.stat().st_mtime localtime = time.time() fileage = float(localtime - last_mod_time) / 3600.0 return fileageThis check returns number of hours since file was last modified, you can include a default 'number of hours between changes' and update the files based on their age.
remember to addimport time
at top of script.
example, set line 29 from:def get_pages(self, suffixlist, cache=False):
todef get_pages(self, suffixlist, cache=False, update_every=48):
then call determine_file_age to see if an update should be forced:file_age = self.determine_file_age(filename)