From 3eeb475194f3feea2481f14141717c850ea8d11e Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 30 Jun 2024 09:38:02 -0400 Subject: [PATCH] refactor(caching): remove parameters that are always the same --- ibis/backends/__init__.py | 2 -- ibis/common/caching.py | 10 ++++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ibis/backends/__init__.py b/ibis/backends/__init__.py index 86987a2a207c..bfc3f461adb4 100644 --- a/ibis/backends/__init__.py +++ b/ibis/backends/__init__.py @@ -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 diff --git a/ibis/common/caching.py b/ibis/common/caching.py index 0ba453a04ff9..006f57231059 100644 --- a/ibis/common/caching.py +++ b/ibis/common/caching.py @@ -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() @@ -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)