Skip to content

Commit 2a42712

Browse files
committed
remove cache.ttl
1 parent f83bdb5 commit 2a42712

5 files changed

Lines changed: 2 additions & 39 deletions

File tree

openml/_api/clients/http.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@ class HTTPCache:
4444
----------
4545
path : pathlib.Path
4646
Base directory where cache entries are stored.
47-
ttl : int
48-
Time-to-live in seconds. Cached entries older than this value are treated
49-
as expired.
5047
5148
Notes
5249
-----
5350
The cache key is derived from the URL (domain and path components) and query
5451
parameters, excluding the ``api_key`` parameter.
5552
"""
5653

57-
def __init__(self, *, path: Path, ttl: int) -> None:
54+
def __init__(self, *, path: Path) -> None:
5855
self.path = path
59-
self.ttl = ttl
6056

6157
def get_key(self, url: str, params: dict[str, Any]) -> str:
6258
"""
@@ -144,9 +140,6 @@ def load(self, key: str) -> Response:
144140
if created_at is None:
145141
raise ValueError("Cache metadata missing 'created_at'")
146142

147-
if time.time() - created_at > self.ttl:
148-
raise TimeoutError(f"Cache expired for {path}")
149-
150143
with headers_path.open("r", encoding="utf-8") as f:
151144
headers = json.load(f)
152145

openml/_api/setup/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def build(cls, config: Config) -> APIBackendBuilder:
8484
"""
8585
cache_dir = Path(config.cache.dir).expanduser()
8686

87-
http_cache = HTTPCache(path=cache_dir, ttl=config.cache.ttl)
87+
http_cache = HTTPCache(path=cache_dir)
8888
minio_client = MinIOClient(path=cache_dir)
8989

9090
primary_api_config = config.api_configs[config.api_version]

openml/_api/setup/config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass, field
4-
from datetime import timedelta
54

65
from openml.enums import APIVersion, RetryPolicy
76

@@ -54,12 +53,9 @@ class CacheConfig:
5453
----------
5554
dir : str
5655
Path to the directory where cached files will be stored.
57-
ttl : int
58-
Time-to-live for cached entries, in seconds.
5956
"""
6057

6158
dir: str
62-
ttl: int
6359

6460

6561
@dataclass
@@ -111,6 +107,5 @@ class Config:
111107
cache: CacheConfig = field(
112108
default_factory=lambda: CacheConfig(
113109
dir=str(_resolve_default_cache_dir()),
114-
ttl=int(timedelta(weeks=1).total_seconds()),
115110
)
116111
)

openml/testing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,10 @@ def setUp(self, n_levels: int = 1, tmpdir_suffix: str = "") -> None:
291291

292292
retries = self.connection_n_retries
293293
retry_policy = RetryPolicy.HUMAN if self.retry_policy == "human" else RetryPolicy.ROBOT
294-
ttl = openml._backend.get_config_value("cache.ttl")
295294
cache_dir = self.static_cache_dir
296295

297296
self.cache = HTTPCache(
298297
path=cache_dir,
299-
ttl=ttl,
300298
)
301299
self.http_clients = {
302300
APIVersion.V1: HTTPClient(

tests/test_api/test_http.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,6 @@ def test_get_uses_cached_response(self):
105105
self.assertEqual(response1.content, response2.content)
106106
self.assertEqual(response1.status_code, response2.status_code)
107107

108-
@pytest.mark.uses_test_server()
109-
def test_get_cache_expires(self):
110-
# force short TTL
111-
self.cache.ttl = 1
112-
path = "task/1"
113-
114-
url = self._prepare_url(path=path)
115-
key = self.cache.get_key(url, {})
116-
cache_path = self.cache._key_to_path(key) / "meta.json"
117-
118-
response1 = self.http_client.get(path, use_cache=True)
119-
response1_cache_time_stamp = cache_path.stat().st_ctime
120-
121-
time.sleep(2)
122-
123-
response2 = self.http_client.get(path, use_cache=True)
124-
response2_cache_time_stamp = cache_path.stat().st_ctime
125-
126-
# cache expired -> new request
127-
self.assertNotEqual(response1_cache_time_stamp, response2_cache_time_stamp)
128-
self.assertEqual(response2.status_code, 200)
129-
self.assertEqual(response1.content, response2.content)
130-
131108
@pytest.mark.uses_test_server()
132109
def test_get_reset_cache(self):
133110
path = "task/1"

0 commit comments

Comments
 (0)