feat: adds caching per namespace #67

Merged
HideyoshiNakazone merged 3 commits from feature/cache-per-namespace into main 2025-11-26 18:28:17 +00:00
HideyoshiNakazone commented 2025-11-26 18:05:46 +00:00 (Migrated from github.com)

This pull request refactors the reference cache mechanism in the SchemaConverter class to support multiple isolated namespaces for schema references, improving schema model isolation and cache management. The changes also introduce comprehensive tests to verify correct behavior for reference caching, namespace isolation, and cache clearing.

Refactoring reference cache to support namespaces

  • Changed the SchemaConverter to use a namespace_registry (dictionary of reference caches keyed by schema $id or namespace) instead of a single reference cache, enabling isolated caches per schema namespace. (jambo/schema_converter.py)
  • Updated the build_with_cache method to select or create a reference cache based on the schema's $id, ensuring models from different schemas do not collide in the cache. (jambo/schema_converter.py)
  • Refactored clear_ref_cache and get_cached_ref methods to operate on a specific namespace, allowing targeted or global cache clearing and lookup. (jambo/schema_converter.py)

Enhancements to test coverage

  • Added new test cases to verify cache isolation between schemas with different $ids, collision when $id matches, namespace-based cache lookup, and clearing of namespace-specific caches. (tests/test_schema_converter.py)
  • Removed the assertion checking for shared reference cache between converter instances, as the cache is now managed per namespace. (tests/test_schema_converter.py)
This pull request refactors the reference cache mechanism in the `SchemaConverter` class to support multiple isolated namespaces for schema references, improving schema model isolation and cache management. The changes also introduce comprehensive tests to verify correct behavior for reference caching, namespace isolation, and cache clearing. ### Refactoring reference cache to support namespaces * Changed the `SchemaConverter` to use a `namespace_registry` (dictionary of reference caches keyed by schema `$id` or namespace) instead of a single reference cache, enabling isolated caches per schema namespace. (`jambo/schema_converter.py`) * Updated the `build_with_cache` method to select or create a reference cache based on the schema's `$id`, ensuring models from different schemas do not collide in the cache. (`jambo/schema_converter.py`) * Refactored `clear_ref_cache` and `get_cached_ref` methods to operate on a specific namespace, allowing targeted or global cache clearing and lookup. (`jambo/schema_converter.py`) ### Enhancements to test coverage * Added new test cases to verify cache isolation between schemas with different `$id`s, collision when `$id` matches, namespace-based cache lookup, and clearing of namespace-specific caches. (`tests/test_schema_converter.py`) * Removed the assertion checking for shared reference cache between converter instances, as the cache is now managed per namespace. (`tests/test_schema_converter.py`)
codecov[bot] commented 2025-11-26 18:08:13 +00:00 (Migrated from github.com)

Codecov Report

All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

## [Codecov](https://app.codecov.io/gh/HideyoshiNakazone/jambo/pull/67?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vitor+Hideyoshi) Report :white_check_mark: All modified and coverable lines are covered by tests. :loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)
Sign in to join this conversation.