File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed
Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ The ``validate`` helper keeps an internal compiled-validator cache. You can
9898control 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
102104To validate an OpenAPI schema:
103105
Original file line number Diff line number Diff 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
9696See :doc: `validation ` for runtime behavior details.
9797
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ skip schema checking.
4242The shortcut keeps an internal compiled-validator cache.
4343Use ``OPENAPI_SCHEMA_VALIDATOR_COMPILED_VALIDATOR_CACHE_MAX_SIZE `` to control cache
4444capacity (default: ``128 ``).
45+ The setting is read once at first use and then cached for the process lifetime.
4546
4647To validate an OpenAPI schema:
4748
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments