Skip to content

Commit

Permalink
#209: Add client cache size as a configurable option
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Mar 15, 2021
1 parent 3c202a8 commit fb20095
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"backend": "db",
"client_cache_size": 28,
"DB_URL": "mysql+pymysql://icatdbuser:icatdbuserpw@localhost:3306/icatdb",
"ICAT_URL": "https://localhost:8181",
"icat_check_cert": false,
Expand Down
6 changes: 6 additions & 0 deletions datagateway_api/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def set_backend_type(self, backend_type):
"""
self.config["backend"] = backend_type

def get_client_cache_size(self):
try:
return self.config["client_cache_size"]
except KeyError:
sys.exit("Missing config value, client_cache_size")

def get_db_url(self):
try:
return self.config["DB_URL"]
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def wrapper_requires_session(*args, **kwargs):
return wrapper_requires_session


@lru_cache(maxsize=28)
@lru_cache(maxsize=config.get_client_cache_size())
def get_cached_client(session_id):
"""
TODO - Add docstring
Expand Down
10 changes: 10 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def test_invalid_backend_type(self, invalid_config):
invalid_config.get_backend_type()


class TestGetClientCacheSize:
def test_valid_client_cache_size(self, valid_config):
cache_size = valid_config.get_client_cache_size()
assert cache_size == 28

def test_invalid_client_cache_size(self, invalid_config):
with pytest.raises(SystemExit):
invalid_config.get_client_cache_size()


class TestGetDBURL:
def test_valid_db_url(self, valid_config):
db_url = valid_config.get_db_url()
Expand Down

0 comments on commit fb20095

Please sign in to comment.