Skip to content

Commit 92d88e4

Browse files
committed
Merge branch 'migration' of https://github.com/geetu040/openml-python into flow-migration-stacked
2 parents c7c24a3 + c9617f9 commit 92d88e4

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

openml/_api/clients/http.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def request(
327327
path: str,
328328
*,
329329
use_cache: bool = False,
330+
reset_cache: bool = False,
330331
use_api_key: bool = False,
331332
**request_kwargs: Any,
332333
) -> Response:
@@ -350,7 +351,7 @@ def request(
350351
timeout = request_kwargs.pop("timeout", self.timeout)
351352
files = request_kwargs.pop("files", None)
352353

353-
if use_cache and self.cache is not None:
354+
if use_cache and not reset_cache and self.cache is not None:
354355
cache_key = self.cache.get_key(url, params)
355356
try:
356357
return self.cache.load(cache_key)
@@ -384,6 +385,7 @@ def request(
384385
assert response is not None
385386

386387
if use_cache and self.cache is not None:
388+
cache_key = self.cache.get_key(url, params)
387389
self.cache.save(cache_key, response)
388390

389391
return response
@@ -393,13 +395,15 @@ def get(
393395
path: str,
394396
*,
395397
use_cache: bool = False,
398+
reset_cache: bool = False,
396399
use_api_key: bool = False,
397400
**request_kwargs: Any,
398401
) -> Response:
399402
return self.request(
400403
method="GET",
401404
path=path,
402405
use_cache=use_cache,
406+
reset_cache=reset_cache,
403407
use_api_key=use_api_key,
404408
**request_kwargs,
405409
)

tests/test_api/test_http.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ def test_get_cache_expires(self):
103103
self.assertEqual(response2.status_code, 200)
104104
self.assertEqual(response1.content, response2.content)
105105

106+
@pytest.mark.uses_test_server()
107+
def test_get_reset_cache(self):
108+
path = "task/1"
109+
110+
url = self._get_url(path=path)
111+
key = self.cache.get_key(url, {})
112+
cache_path = self.cache._key_to_path(key) / "meta.json"
113+
114+
response1 = self.http_client.get(path, use_cache=True)
115+
response1_cache_time_stamp = cache_path.stat().st_ctime
116+
117+
response2 = self.http_client.get(path, use_cache=True, reset_cache=True)
118+
response2_cache_time_stamp = cache_path.stat().st_ctime
119+
120+
self.assertNotEqual(response1_cache_time_stamp, response2_cache_time_stamp)
121+
self.assertEqual(response2.status_code, 200)
122+
self.assertEqual(response1.content, response2.content)
123+
106124
@pytest.mark.uses_test_server()
107125
def test_post_and_delete(self):
108126
task_xml = """

0 commit comments

Comments
 (0)