Test cache management#

import lamindb_setup as ln_setup
from lamindb_setup.dev._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://lndb-setup-ci", name="test-cache")

Check that setting the cache dir works.

assert not system_storage_settings_file().exists()
save_cache_dir = ln_setup.settings.storage.cache_dir
set_cache_dir = save_cache_dir.parent / "Cache1"
ln_setup.settings.storage.cache_dir = set_cache_dir
assert system_storage_settings_file().exists()
assert ln_setup.settings.storage.cache_dir != save_cache_dir
assert ln_setup.settings.storage.cache_dir == set_cache_dir
assert set_cache_dir.exists()
assert set_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(set_cache_dir.iterdir())

Check that the cache dir is preserved betweenclose and load.

ln_setup.load("test-cache")
assert ln_setup.settings.storage.cache_dir == set_cache_dir

Setting to "null" or None restores the default directory.

ln_setup.settings.storage.cache_dir = None
assert ln_setup.settings.storage.cache_dir == save_cache_dir
assert ln_setup.settings.storage.cache_dir != set_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.

!lamin cache
!lamin cache set "null"

Clean up.

system_storage_settings_file().unlink()
ln_setup.delete("test-cache", force=True)