Skip to content

Commit c4dae43

Browse files
committed
rename: use_cache -> enable_cache; reset_cache -> refresh_cache
1 parent 164f66f commit c4dae43

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

openml/_api/clients/http.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ def request( # noqa: PLR0913, C901
550550
method: str,
551551
path: str,
552552
*,
553-
use_cache: bool = False,
554-
reset_cache: bool = False,
553+
enable_cache: bool = False,
554+
refresh_cache: bool = False,
555555
use_api_key: bool = False,
556556
md5_checksum: str | None = None,
557557
**request_kwargs: Any,
@@ -565,10 +565,11 @@ def request( # noqa: PLR0913, C901
565565
HTTP method to use.
566566
path : str
567567
API path relative to the base URL.
568-
use_cache : bool, optional
569-
Whether to load/store responses from cache.
570-
reset_cache : bool, optional
571-
If True, bypass existing cache entries.
568+
enable_cache : bool, optional
569+
Whether to load/store response from cache.
570+
refresh_cache : bool, optional
571+
Only used when `enable_cache=True`. If True, ignore any existing
572+
cached response and overwrite it with a fresh one.
572573
use_api_key : bool, optional
573574
Whether to include the API key in query parameters.
574575
md5_checksum : str or None, optional
@@ -607,7 +608,7 @@ def request( # noqa: PLR0913, C901
607608

608609
files = request_kwargs.pop("files", None)
609610

610-
if use_cache and not reset_cache:
611+
if enable_cache and not refresh_cache:
611612
cache_key = self.cache.get_key(url, params)
612613
try:
613614
return self.cache.load(cache_key)
@@ -646,7 +647,7 @@ def request( # noqa: PLR0913, C901
646647
if md5_checksum is not None:
647648
self._verify_checksum(response, md5_checksum)
648649

649-
if use_cache:
650+
if enable_cache:
650651
cache_key = self.cache.get_key(url, params)
651652
self.cache.save(cache_key, response)
652653

@@ -680,8 +681,8 @@ def get(
680681
self,
681682
path: str,
682683
*,
683-
use_cache: bool = False,
684-
reset_cache: bool = False,
684+
enable_cache: bool = False,
685+
refresh_cache: bool = False,
685686
use_api_key: bool = False,
686687
md5_checksum: str | None = None,
687688
**request_kwargs: Any,
@@ -693,9 +694,9 @@ def get(
693694
----------
694695
path : str
695696
API path relative to the base URL.
696-
use_cache : bool, optional
697+
enable_cache : bool, optional
697698
Whether to use the response cache.
698-
reset_cache : bool, optional
699+
refresh_cache : bool, optional
699700
Whether to ignore existing cached entries.
700701
use_api_key : bool, optional
701702
Whether to include the API key.
@@ -712,8 +713,8 @@ def get(
712713
return self.request(
713714
method="GET",
714715
path=path,
715-
use_cache=use_cache,
716-
reset_cache=reset_cache,
716+
enable_cache=enable_cache,
717+
refresh_cache=refresh_cache,
717718
use_api_key=use_api_key,
718719
md5_checksum=md5_checksum,
719720
**request_kwargs,
@@ -746,7 +747,7 @@ def post(
746747
return self.request(
747748
method="POST",
748749
path=path,
749-
use_cache=False,
750+
enable_cache=False,
750751
use_api_key=use_api_key,
751752
**request_kwargs,
752753
)
@@ -774,7 +775,7 @@ def delete(
774775
return self.request(
775776
method="DELETE",
776777
path=path,
777-
use_cache=False,
778+
enable_cache=False,
778779
use_api_key=True,
779780
**request_kwargs,
780781
)

tests/test_api/test_http.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_get(self):
7777

7878
@pytest.mark.uses_test_server()
7979
def test_get_with_cache_creates_cache(self):
80-
response = self.http_client.get("task/1", use_cache=True)
80+
response = self.http_client.get("task/1", enable_cache=True)
8181

8282
self.assertEqual(response.status_code, 200)
8383
self.assertTrue(self.cache.path.exists())
@@ -96,26 +96,26 @@ def test_get_with_cache_creates_cache(self):
9696
@pytest.mark.uses_test_server()
9797
def test_get_uses_cached_response(self):
9898
# first request populates cache
99-
response1 = self.http_client.get("task/1", use_cache=True)
99+
response1 = self.http_client.get("task/1", enable_cache=True)
100100

101101
# second request should load from cache
102-
response2 = self.http_client.get("task/1", use_cache=True)
102+
response2 = self.http_client.get("task/1", enable_cache=True)
103103

104104
self.assertEqual(response1.content, response2.content)
105105
self.assertEqual(response1.status_code, response2.status_code)
106106

107107
@pytest.mark.uses_test_server()
108-
def test_get_reset_cache(self):
108+
def test_get_refresh_cache(self):
109109
path = "task/1"
110110

111111
url = self._prepare_url(path=path)
112112
key = self.cache.get_key(url, {})
113113
cache_path = self.cache._key_to_path(key) / "meta.json"
114114

115-
response1 = self.http_client.get(path, use_cache=True)
115+
response1 = self.http_client.get(path, enable_cache=True)
116116
response1_cache_time_stamp = cache_path.stat().st_ctime
117117

118-
response2 = self.http_client.get(path, use_cache=True, reset_cache=True)
118+
response2 = self.http_client.get(path, enable_cache=True, refresh_cache=True)
119119
response2_cache_time_stamp = cache_path.stat().st_ctime
120120

121121
self.assertNotEqual(response1_cache_time_stamp, response2_cache_time_stamp)

0 commit comments

Comments
 (0)