#68 Refactor cache settings
Merged 3 years ago by frantisekz. Opened 3 years ago by frantisekz.

file modified
+9 -3
@@ -15,14 +15,20 @@ 

  CELERY_BROKER_URL = 'redis://localhost:6379'

  CELERY_RESULT_BACKEND = 'redis://localhost:6379'

  

- # MAX_DB_AGE will be ignored if FORCE_CACHED_DATA, DB cache will be used no matter how old it is

+ # MAX_DB_AGE will be ignored as per IGNORE_CACHE_TIMESTAMP setting bellow, data from caches might be used no matter their age

  # make sure to set up cron with "runcli.py sync" if set to True

  # The idea is to have sync run every hour and leave MAX_DB_AGE big enough not to drop local_cache

  # before sync finishes

- FORCE_CACHED_DATA = False

+ MAX_DB_AGE = 14400 # Max cache age allowed in seconds (240 minutes)

+ 

+ # IGNORE_CACHE_TIMESTAMP sets how oraculum verifies data aga in cache

+ # values can be 'local', 'db' or None

+ # "local" - always trust both local and database caches, plan refresh if database data are missing

+ # "db" - verify only local cache age, always trust database cache, plan refresh if database data are missing

+ # None - verify age of both, local and database caches, plan refresh if data are too old

+ IGNORE_CACHE_TIMESTAMP = 'db'

  

  ENABLE_LOCAL_CACHE = True

- MAX_DB_AGE = 14400 # Max cache age allowed in seconds (240 minutes)

  

  ACTIVITY_REQUIRED = 14 # Cache data for users who used the service in at least last 14 days

  

file modified
+8 -1
@@ -50,7 +50,14 @@ 

      CELERY_RESULT_BACKEND = 'redis://localhost:6379'

  

      ENABLE_LOCAL_CACHE = True

-     FORCE_CACHED_DATA = False

+ 

+     # IGNORE_CACHE_TIMESTAMP sets how oraculum verifies data aga in cache

+     # values can be 'local', 'db' or None

+     # "local" - always trust both local and database caches, plan refresh if database data are missing

+     # "db" - verify only local cache age, always trust database cache, plan refresh if database data are missing

+     # None - verify age of both, local and database caches, plan refresh if data are too old

+     IGNORE_CACHE_TIMESTAMP = 'db'

+ 

      MAX_DB_AGE = 14400  # keep data cached for 240 minutes

      ACTIVITY_REQUIRED = 14  # cache users who used the service in at least last 14 days

  

@@ -159,7 +159,10 @@ 

      def _new_enough(self, cached_object):

          if cached_object is None:

              return False

-         if app.config['FORCE_CACHED_DATA']:

+         if app.config['IGNORE_CACHE_TIMESTAMP'] == "local":

+             return True

+         # If cached_object is an instance of CachedData, it is from the database

+         if app.config['IGNORE_CACHE_TIMESTAMP'] == "db" and isinstance(cached_object, CachedData):

              return True

          if datetime.datetime.utcnow() > cached_object.time_created + self.max_cache_age:

              return False

no initial comment

Maybe add a comment explaining what's going on here.

Other than the nitpick above, LGTM

rebased onto 2833c1a

3 years ago

Pull-Request has been merged by frantisekz

3 years ago