Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(caching): remove parameters that are always the same #9532

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ def __init__(self, *args, **kwargs):
populate=self._load_into_cache,
lookup=lambda name: self.table(name).op(),
finalize=self._clean_up_cached_table,
generate_name=functools.partial(util.gen_name, "cache"),
key=lambda expr: expr.op(),
)

@property
Expand Down
10 changes: 4 additions & 6 deletions ibis/common/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ def __init__(
populate: Callable[[str, Any], None],
lookup: Callable[[str], Any],
finalize: Callable[[Any], None],
generate_name: Callable[[], str],
key: Callable[[Any], Any],
) -> None:
self.populate = populate
self.lookup = lookup
self.finalize = finalize
self.generate_name = generate_name
self.key = key or (lambda x: x)

self.cache: dict[Any, CacheEntry] = dict()

Expand All @@ -70,8 +66,10 @@ def __getitem__(self, key):

def store(self, input):
"""Compute and store a reference to `key`."""
key = self.key(input)
name = self.generate_name()
from ibis.util import gen_name

key = input.op()
name = gen_name("cache")
self.populate(name, input)
cached = self.lookup(name)
finalizer = finalize(cached, self._release, key)
Expand Down