Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep caching disabled by default #809

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion arctic/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class FwPointersCfg(Enum):
# -------------------------------
# Flag used for indicating caching levels. For now just for list_libraries.
# -------------------------------
ENABLE_CACHE = not bool(os.environ.get('ARCTIC_DISABLE_CACHE'))
ENABLE_CACHE = bool(os.environ.get('ENABLE_CACHE'))

# -------------------------------
# Currently we try to bson encode if the data is less than a given size and store it in
Expand Down
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