Skip to content

Commit 924b8a3

Browse files
sebastjaegerSebastian Jäger
andauthored
feat: Cache get_any_feature_view results (#5175)
Cache get_any_feature_view results Signed-off-by: Sebastian Jäger <[email protected]> Co-authored-by: Sebastian Jäger <[email protected]>
1 parent 3674971 commit 924b8a3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

sdk/python/feast/infra/registry/proto_registry_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ def wrapper(
7171
return wrapper
7272

7373

74+
def registry_proto_cache_name(func):
75+
cache_proto_key = None
76+
cache = {}
77+
78+
@wraps(func)
79+
def wrapper(registry_proto: RegistryProto, name: str, project: str):
80+
nonlocal cache_proto_key, cache
81+
82+
proto_key = (id(registry_proto), registry_proto.version_id)
83+
84+
if proto_key != cache_proto_key:
85+
cache = {}
86+
cache_proto_key = proto_key
87+
88+
key = (project, name)
89+
if key in cache:
90+
return cache[key]
91+
else:
92+
value = func(registry_proto, name, project)
93+
cache[key] = value
94+
return value
95+
96+
return wrapper
97+
98+
7499
def get_project_metadata(
75100
registry_proto: Optional[RegistryProto], project: str
76101
) -> Optional[ProjectMetadataProto]:
@@ -94,6 +119,7 @@ def get_feature_service(
94119
raise FeatureServiceNotFoundException(name, project=project)
95120

96121

122+
@registry_proto_cache_name
97123
def get_any_feature_view(
98124
registry_proto: RegistryProto, name: str, project: str
99125
) -> BaseFeatureView:

0 commit comments

Comments
 (0)