pallets-eco / flask-caching

A caching extension for Flask
https://flask-caching.readthedocs.io
Other
885 stars 192 forks source link

Access cached value inside forced_update #392

Open daviddavo opened 2 years ago

daviddavo commented 2 years ago

I have an application with data that is updated every couple days. Thusly, the default cache timeout is of 24 hours. Nevertheless, I want to force the update when the source data changes.

I have a method to know when the data changes, called get_last_data_updated(). Also, the date is saved when the result of a function is memoized, so I can do returned_object.last_update.

I want to add a forced_update callable to the memoized function with the following behaviour:

def forced_update(cached_obj):
  return get_last_data_updated() > cached_obj.last_update

Nevertheless, I don't know how to access the cached object, only the arguments of the function. How can I accomplish something like this?

misilot commented 11 months ago

@daviddavo did you ever figure this out?

daviddavo commented 11 months ago

No, I ended up not using the library (nor caching) because it wasn't worth the effort at the time.