Add 24-hour TTL to Eurostar price cache
Cache reads now accept an optional ttl (seconds). get_cached checks the file mtime and returns None if the entry is older than the TTL, triggering a fresh fetch. Eurostar prices use a 24-hour TTL; timetable caches remain indefinite (date-scoped keys become irrelevant once the date passes). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0dee942e16
commit
6b044b9493
4 changed files with 52 additions and 6 deletions
|
|
@ -7,7 +7,7 @@ def _client():
|
|||
|
||||
|
||||
def _stub_data(monkeypatch, prices=None):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
|
|
@ -94,7 +94,7 @@ def test_results_title_and_social_meta_include_destination(monkeypatch):
|
|||
|
||||
|
||||
def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
|
|
@ -166,7 +166,7 @@ def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypa
|
|||
|
||||
|
||||
def test_results_shows_unreachable_morning_eurostar_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
|
|
@ -233,7 +233,7 @@ def test_results_shows_eurostar_price_and_total(monkeypatch):
|
|||
|
||||
|
||||
def test_results_can_show_only_unreachable_morning_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key, ttl=None: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue