feat(cache): cache game/localization versions from /metadata with configurable TTL - #117
Merged
Conversation
Constructing a SwgohComlinkException logged an error-level traceback via logger.exception() even for expected, caught validation errors, and calling it outside an except block emitted 'NoneType: None' tracebacks. Callers own logging context; the constructor override is removed along with the now-moot B904 per-file ruff ignore.
The /metadata request schema requires the camelCase 'clientSpecs' key and declares additionalProperties: false, so the snake_case 'client_specs' key sent by get_game_metadata() was rejected by the server. Verified against the comlink OpenAPI spec (v0.40.1).
…figurable TTL Version-less get_game_data(), get_localization(), and get_latest_game_data_version() calls previously made a fresh /metadata round-trip every time. Both clients now cache latestGamedataVersion and latestLocalizationBundleVersion on the instance for version_cache_ttl seconds (default 3600). Cold-cache lookups single-flight behind a threading.Lock (sync) or asyncio.Lock (async), successful get_game_metadata() calls refresh the cache opportunistically, and explicit version arguments always bypass it. Set version_cache_ttl=0 to restore the previous uncached behavior, math.inf to cache for the client lifetime, or call invalidate_version_cache() / pass refresh=True to force a re-fetch.
This was referenced Aug 3, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an instance-level version cache so version-less
get_game_data(),get_localization(), andget_latest_game_data_version()calls no longer make a fresh/metadataround-trip every time, plus two bug fixes picked up along the way.Fixes #116
Version cache (
8cdd771)SwgohComlinkandSwgohComlinkAsyncnow cachelatestGamedataVersionandlatestLocalizationBundleVersionon the instance forversion_cache_ttlseconds (default 3600).threading.Lock(sync) /asyncio.Lock(async) so concurrent callers don't stampede/metadata.get_game_metadata()calls refresh the cache opportunistically; explicit version arguments always bypass it.version_cache_ttl=0restores the previous uncached behavior,math.infcaches for the client lifetime, andinvalidate_version_cache()/refresh=Trueforce a re-fetch.Fix:
/metadatapayload key (1909912) — fixes #116get_game_metadata()sent the snake_caseclient_specskey, but the comlink/metadatarequest schema requires camelCaseclientSpecsand declaresadditionalProperties: false, so requests with client specs were rejected by the server. Verified against the comlink OpenAPI spec (v0.40.1). The mocked unit tests asserted the wrong key and were updated alongside the fix.Fix: exception constructor logging (
f841fa8)Constructing a
SwgohComlinkExceptionlogged an error-level traceback vialogger.exception()even for expected, caught validation errors, and emittedNoneType: Nonetracebacks outside anexceptblock. The constructor override is removed; callers own logging context.Testing
tests/unit/test_version_cache.py(214 lines) covering TTL expiry, single-flight behavior, opportunistic refresh, explicit-version bypass, invalidation, andrefresh=Truefor both clients.tests/unit/test_exceptions.pycases asserting constructors no longer log.clientSpecskey.🤖 Generated with Claude Code