Jul-18-2021, 08:21 AM
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:
remember to add
example, set line 29 from:
to
then call determine_file_age to see if an update should be forced:
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 add
import time
at top of script.example, set line 29 from:
def get_pages(self, suffixlist, cache=False):
to
def 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)