Skip to content

Commit

Permalink
Fix test broken by changing the default
Browse files Browse the repository at this point in the history
Also fix the get_caching_state function and comment.
  • Loading branch information
shashank88 committed Nov 4, 2019
1 parent 2541e50 commit c908407
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
19 changes: 8 additions & 11 deletions arctic/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
CACHE_SETTINGS = 'settings'
CACHE_SETTINGS_KEY = 'cache'
"""
Sample cache_settings collection entry:
meta_db.cache_settings.insertOne({"type": "cache", "enabled": true, "cache_expiry": 600})
meta_db.cache_settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "type": "cache", "enabled" : false, "cache_expiry" : 600 }
Sample settings collection entry:
meta_db.settings.insertOne({"type": "cache", "enabled": true, "cache_expiry": 600})
meta_db.settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "type": "cache", "enabled" : false, "cache_expiry" : 600 }
"""
DEFAULT_CACHE_EXPIRY = 3600

Expand Down Expand Up @@ -46,7 +46,7 @@ def set_caching_state(self, enabled):
logging.error("Enabled should be a boolean type.")
return

if CACHE_SETTINGS not in self._cachedb.list_collection_names():
if (CACHE_SETTINGS not in self._cachedb.list_collection_names()) or self._cachedb[CACHE_SETTINGS].count() == 0:
logging.info("Creating %s collection for cache settings" % CACHE_SETTINGS)
self._cachedb[CACHE_SETTINGS].insert_one({
'type': CACHE_SETTINGS_KEY,
Expand Down Expand Up @@ -129,10 +129,7 @@ def update_item_for_key(self, key, old, new):

def is_caching_enabled(self, cache_enabled_in_env):
cache_settings = self._get_cache_settings()
# Caching is enabled unless explicitly disabled. Can be disabled either by an env variable or config in mongo.
if cache_settings and not cache_settings['enabled']:
return False
# Disabling from Mongo Setting take precedence over this env variable
if not cache_enabled_in_env:
return False
return True
# Explicitly setting the setting takes precedence over env.
if cache_settings:
return cache_settings['enabled']
return cache_enabled_in_env
1 change: 0 additions & 1 deletion tests/integration/test_arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def test_disable_cache_by_settings(arctic):

# Should be enabled by default
assert arctic._list_libraries_cached() == arctic._list_libraries()

arctic._cache.set_caching_state(enabled=False)

# Should not return cached results now.
Expand Down

0 comments on commit c908407

Please sign in to comment.