Skip to content

Commit 2fd4825

Browse files
committed
Clarify env var lietime
1 parent 68b2bfd commit 2fd4825

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ The ``validate`` helper keeps an internal compiled-validator cache. You can
9898
control cache size using the
9999
``OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE`` environment variable
100100
(default: ``128``).
101+
The value is loaded once at first use and reused for the lifetime of the
102+
process.
101103

102104
To validate an OpenAPI schema:
103105

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Environment variables:
9191

9292
* ``OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE``
9393
Maximum number of compiled validators kept by the ``validate`` shortcut
94-
cache. Default: ``128``.
94+
cache. Default: ``128``. Loaded once at first use.
9595

9696
See :doc:`validation` for runtime behavior details.
9797

docs/validation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ skip schema checking.
4242
The shortcut keeps an internal compiled-validator cache.
4343
Use ``OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE`` to control cache
4444
capacity (default: ``128``).
45+
The setting is read once at first use and then cached for the process lifetime.
4546

4647
To validate an OpenAPI schema:
4748

tests/unit/test_settings.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from openapi_schema_validator.settings import get_settings
2+
from openapi_schema_validator.settings import reset_settings_cache
3+
4+
5+
def test_compiled_validator_cache_size_env_is_cached(monkeypatch):
6+
monkeypatch.setenv(
7+
"OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE",
8+
"11",
9+
)
10+
reset_settings_cache()
11+
12+
first = get_settings()
13+
assert first.compiled_validator_cache_max_size == 11
14+
15+
monkeypatch.setenv(
16+
"OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE",
17+
"3",
18+
)
19+
second = get_settings()
20+
assert second.compiled_validator_cache_max_size == 11
21+
22+
reset_settings_cache()
23+
third = get_settings()
24+
assert third.compiled_validator_cache_max_size == 3

0 commit comments

Comments
 (0)