Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions sdk/python/feast/infra/registry/proto_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ def wrapper(
return wrapper


def registry_proto_cache_name(func):
cache_proto_key = None
cache = {}

@wraps(func)
def wrapper(registry_proto: RegistryProto, name: str, project: str):
nonlocal cache_proto_key, cache

proto_key = (id(registry_proto), registry_proto.version_id)

if proto_key != cache_proto_key:
cache = {}
cache_proto_key = proto_key

key = (project, name)
if key in cache:
return cache[key]
else:
value = func(registry_proto, name, project)
cache[key] = value
return value

return wrapper


def get_project_metadata(
registry_proto: Optional[RegistryProto], project: str
) -> Optional[ProjectMetadataProto]:
Expand All @@ -94,6 +119,7 @@ def get_feature_service(
raise FeatureServiceNotFoundException(name, project=project)


@registry_proto_cache_name

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this would be preferred to functools.cache or functools.lru_cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard lru cache will not be able to do the caching out of the box, since Registry is an unhashable type. Further, with the lru cache, we can only define a max size, which might not necessarily be sufficient if it is exceeded by the number of feature views. Here we also only keep the cache for the last seen registry/version and discard it otherwise to ensure that the cache cannot keep growing infinitely.

Note that the implementation is inspired by https://github.com/feast-dev/feast/blob/master/sdk/python/feast/infra/registry/proto_registry_utils.py#L30.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the thorough response!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!

def get_any_feature_view(
registry_proto: RegistryProto, name: str, project: str
) -> BaseFeatureView:
Expand Down
Loading