Skip to content

Commit 488c19c

Browse files
authored
Merge pull request #128 from EOPF-Explorer/fix/align-cache-redis-settings-and-ttl-wiring
fix(cache): align Redis settings and fix Helm env-var wiring for cache TTLs
2 parents 9a6ad00 + 102ae3f commit 488c19c

10 files changed

Lines changed: 48 additions & 16 deletions

File tree

helm/charts/CACHE_CONFIG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ The chart automatically generates the following environment variables based on c
8989
### Cache Control
9090
- `TITILER_EOPF_CACHE_ENABLE`: "true" when cache is enabled
9191
- `TITILER_EOPF_CACHE_BACKEND`: Backend type (redis/s3/s3-redis)
92-
- `TITILER_EOPF_CACHE_TTL_DEFAULT`: Default TTL in seconds
92+
- `TITILER_EOPF_CACHE_DEFAULT_TTL`: Default TTL in seconds
93+
- `TITILER_EOPF_CACHE_TILE_TTL`: Tile cache TTL in seconds
94+
- `TITILER_EOPF_CACHE_METADATA_TTL`: TTL for cached datatrees (from `cache.ttl.datasets`)
95+
- `TITILER_EOPF_CACHE_VERSION_PROBE_TTL`: Store-version probe throttle (0 disables probing)
9396
- `TITILER_EOPF_CACHE_NAMESPACE`: Cache key namespace
9497

9598
### Redis Configuration
9699
- `TITILER_EOPF_CACHE_REDIS_HOST`: Redis hostname
97100
- `TITILER_EOPF_CACHE_REDIS_PORT`: Redis port
98-
- `TITILER_EOPF_CACHE_REDIS_DATABASE`: Redis database number
101+
- `TITILER_EOPF_CACHE_REDIS_DB`: Redis database number
99102
- `TITILER_EOPF_CACHE_REDIS_PASSWORD`: Redis password (from secret)
100103

101104
### S3 Configuration

helm/charts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ See [CACHE_CONFIG.md](CACHE_CONFIG.md) for detailed configuration guide.
4848
| `cache.backend` | Cache backend: `redis`, `s3`, or `s3-redis` | `redis` |
4949
| `cache.ttl.default` | Default TTL in seconds | `3600` |
5050
| `cache.ttl.tiles` | Tile cache TTL in seconds | `3600` |
51-
| `cache.ttl.datasets` | Dataset cache TTL in seconds | `1800` |
51+
| `cache.ttl.datasets` | Dataset (datatree metadata) cache TTL in seconds | `1800` |
5252
| `cache.namespace` | Cache key namespace | `titiler-eopf` |
5353

5454
### Redis Cache Configuration

helm/charts/examples/cache-external-redis-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cache:
2222
default: 1800 # 30 minutes
2323
tiles: 3600 # 1 hour
2424
datasets: 900 # 15 minutes
25-
25+
2626
namespace: "staging-cache"
2727
exclude_params:
2828
- "debug"

helm/charts/examples/cache-redis-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cache:
1515
default: 3600
1616
tiles: 3600
1717
datasets: 1800
18-
18+
1919
namespace: "dev-cache"
2020

2121
# Admin API

helm/charts/examples/cache-s3-redis-values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ cache:
3131
# Cache settings for production
3232
ttl:
3333
default: 7200 # 2 hours
34-
tiles: 14400 # 4 hours
34+
tiles: 14400 # 4 hours
3535
datasets: 3600 # 1 hour
36-
36+
3737
namespace: "prod-cache"
3838

3939
# Admin API

helm/charts/templates/deployment.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ spec:
4444
value: "true"
4545
- name: TITILER_EOPF_CACHE_BACKEND
4646
value: {{ .Values.cache.backend | quote }}
47-
- name: TITILER_EOPF_CACHE_TTL_DEFAULT
47+
- name: TITILER_EOPF_CACHE_DEFAULT_TTL
4848
value: {{ .Values.cache.ttl.default | quote }}
49-
- name: TITILER_EOPF_CACHE_TTL_TILES
49+
- name: TITILER_EOPF_CACHE_TILE_TTL
5050
value: {{ .Values.cache.ttl.tiles | quote }}
51-
- name: TITILER_EOPF_CACHE_TTL_DATASETS
52-
value: {{ .Values.cache.ttl.datasets | quote }}
5351
# TTL the GeoZarr reader actually reads for cached datatrees
5452
# (EOPFCacheSettings.metadata_ttl).
5553
- name: TITILER_EOPF_CACHE_METADATA_TTL
@@ -66,7 +64,7 @@ spec:
6664
- name: TITILER_EOPF_CACHE_REDIS_PORT
6765
value: {{ include "titiler-eopf.cache.redis.port" . | quote }}
6866
{{- if .Values.cache.redis.external.database }}
69-
- name: TITILER_EOPF_CACHE_REDIS_DATABASE
67+
- name: TITILER_EOPF_CACHE_REDIS_DB
7068
value: {{ .Values.cache.redis.external.database | quote }}
7169
{{- end }}
7270
{{- /* Redis Authentication - External Redis */ -}}

helm/charts/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ cache:
8686
ttl:
8787
default: 3600 # 1 hour
8888
tiles: 3600
89-
datasets: 1800 # 30 minutes
89+
datasets: 1800 # 30 minutes (feeds cache metadata_ttl for cached datatrees)
9090

9191
# Store-version probe (stale-on-append protection): TTL in seconds between
9292
# HEAD probes of a store's root zarr.json. Set to 0 to disable probing and

tests/test_settings.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pydantic import ValidationError
55
from pydantic_settings import SettingsConfigDict
66

7-
from titiler.eopf.settings import DataStoreSettings
7+
from titiler.eopf.settings import DataStoreSettings, EOPFCacheSettings
88

99

1010
class IsolatedDataStoreSettings(DataStoreSettings):
@@ -54,3 +54,33 @@ def test_datastore_settings_error(params, monkeypatch):
5454
monkeypatch.delenv("TITILER_EOPF_STORE_PATH", raising=False)
5555
with pytest.raises(ValidationError):
5656
IsolatedDataStoreSettings(**params)
57+
58+
59+
class IsolatedEOPFCacheSettings(EOPFCacheSettings):
60+
"""EOPFCacheSettings without .env loading."""
61+
62+
model_config = SettingsConfigDict(
63+
env_prefix="TITILER_EOPF_CACHE_", env_file=None, extra="ignore"
64+
)
65+
66+
67+
def test_eopf_cache_resolves_redis_db(monkeypatch):
68+
"""EOPFCacheSettings resolves the Redis db from TITILER_EOPF_CACHE_REDIS_DB.
69+
70+
The reader dataset cache and the response/tile cache both connect through
71+
``EOPFCacheSettings.redis``, so a configured ``db`` must propagate to that
72+
shared ``CacheRedisSettings`` — otherwise the two caches would target
73+
different Redis databases.
74+
"""
75+
monkeypatch.setenv("TITILER_EOPF_CACHE_ENABLE", "true")
76+
monkeypatch.setenv("TITILER_EOPF_CACHE_BACKEND", "redis")
77+
monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_HOST", "redis.example")
78+
monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_PORT", "6380")
79+
monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_DB", "3")
80+
81+
settings = IsolatedEOPFCacheSettings()
82+
83+
assert settings.redis is not None
84+
assert settings.redis.host == "redis.example"
85+
assert settings.redis.port == 6380
86+
assert settings.redis.db == 3

titiler/eopf/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RedisCache:
1818

1919
@classmethod
2020
def get_instance(
21-
cls, host: str, port: int, password: SecretStr | None
21+
cls, host: str, port: int, password: SecretStr | None, db: int = 0
2222
) -> redis.ConnectionPool:
2323
"""Get the redis connection pool."""
2424
assert redis, "Redis package needs to be installed to use Redis Cache"
@@ -27,7 +27,7 @@ def get_instance(
2727
host=host,
2828
port=port,
2929
password=password.get_secret_value() if password else None,
30-
db=0,
30+
db=db,
3131
# Use RESP3 to stay aligned with the async cache backend
3232
# (and to work with the fakeredis server used in tests).
3333
protocol=3,

titiler/eopf/reader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def _open_dataset_cached(
199199
settings.redis.host,
200200
settings.redis.port,
201201
settings.redis.password,
202+
settings.redis.db,
202203
)
203204
)
204205

0 commit comments

Comments
 (0)