Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit fbd516b

Browse files
committed
address feedback
1 parent fdce328 commit fbd516b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

gapic/utils/cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def inner(self):
4949

5050
# Thread-local storage for the simple cache dictionary.
5151
# This ensures that parallel generation tasks (if any) do not corrupt each other's cache.
52-
_thread_local = threading.local()
52+
_proto_collisions_cache_state = threading.local()
5353

5454

5555
@contextlib.contextmanager
@@ -67,13 +67,13 @@ def generation_cache_context():
6767
large Proto objects that were pinned during generation.
6868
"""
6969
# Initialize the cache as a standard dictionary.
70-
_thread_local.cache = {}
70+
_proto_collisions_cache_state.resolved_collisions = {}
7171
try:
7272
yield
7373
finally:
7474
# Delete the dictionary to free all memory and pinned objects.
7575
# This is essential to prevent memory leaks in long-running processes.
76-
del _thread_local.cache
76+
del _proto_collisions_cache_state.resolved_collisions
7777

7878

7979
def cached_proto_context(func):
@@ -103,7 +103,7 @@ def cached_proto_context(func):
103103
def wrapper(self, *, collisions, **kwargs):
104104

105105
# 1. Check for active cache (returns None if context is not active)
106-
context_cache = getattr(_thread_local, "cache", None)
106+
context_cache = getattr(_proto_collisions_cache_state, "resolved_collisions", None)
107107

108108
# If we are not inside a generation_cache_context (e.g. unit tests),
109109
# bypass the cache entirely.

tests/unit/utils/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ def with_context(self, collisions, *, skip_fields=False, visited_messages=None):
6969

7070
# 3. Context Cleared
7171
# Everything should be forgotten now.
72-
assert getattr(cache._thread_local, "cache", None) is None
72+
assert getattr(cache._proto_collisions_cache_state, "resolved_collisions", None) is None
7373
assert foo.with_context(collisions={"a"}) == "val-3"

0 commit comments

Comments
 (0)