Skip to content

Commit

Permalink
refactor(caching): remove parameters that are always the same (#9532)
Browse files Browse the repository at this point in the history
Remove some unnecessary parameters from `RefCountedCache`
  • Loading branch information
cpcloud authored Jul 9, 2024
1 parent bd3009a commit afa2848
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
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

0 comments on commit afa2848

Please sign in to comment.