Test cache management¶
import os
import lamindb_setup as ln_setup
from lamindb_setup._cache import set_cache_dir
from lamindb_setup.core._settings_store import system_storage_settings_file
ln_setup.login("testuser2")
if system_storage_settings_file().exists():
system_storage_settings_file().unlink()
ln_setup.init(storage="s3://lamindb-ci/test-cache", name="test-cache")
Check that setting the cache dir works.
assert not system_storage_settings_file().exists()
old_cache_dir = ln_setup.settings.cache_dir
new_cache_dir = old_cache_dir.parent / "Cache1"
set_cache_dir(new_cache_dir)
assert system_storage_settings_file().exists()
assert ln_setup.settings.cache_dir == new_cache_dir
assert new_cache_dir.exists()
assert new_cache_dir in ln_setup.settings.instance._sqlite_file_local.parents
Check clearing the cache dir, also closes the cloud sqlite instance.
!lamin cache clear
assert not any(new_cache_dir.iterdir())
Setting to "null"
or None
restores the default directory.
set_cache_dir("null")
assert ln_setup.settings.cache_dir == old_cache_dir
set_cache_dir(None)
assert ln_setup.settings.cache_dir == old_cache_dir
Setting the cache dir through CLI doesn’t affect the currently loaded settings because it is done in another process and the settings only check the cache dir in settings.env
on init.
Check CLI.
exit_status = os.system("lamin cache get")
assert exit_status == 0
exit_status = os.system("lamin cache set 'null'")
assert exit_status == 0
Clean up.
system_storage_settings_file().unlink()
ln_setup.delete("test-cache", force=True)