Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Nov 21, 2023
1 parent 95a6c82 commit a9b3894
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions vizro-core/src/vizro/managers/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

# _caches = {"simple": Cache(config={"CACHE_TYPE": "SimpleCache"}), "null": Cache(config={"CACHE_TYPE": "NullCache"})}
# don't want this for now but might have in future.
# how to turn cache off? For now just specify nullcache. Maybe in future have _dataset._cache = False as shortcut for
# this. Implementation could be using unless or nullcache or if conditional.


class _Dataset:
Expand All @@ -29,9 +31,8 @@ def __init__(self, load_data: pd_LazyDataFrame, /):
# name should never become public since it's taken from the key in data_manager.
self._name: str = ""

@property
def _cache_arguments(self):
return {"timeout": self._timeout}
# We might also want a _cache_arguments dictionary in future that allows user to customise more than just
# timeout, but no rush to do this.

def __call__(self) -> pd.DataFrame:
# In future this will probably take arguments that are passed through to _load_data in order to re-run the
Expand All @@ -50,7 +51,7 @@ def __call__(self) -> pd.DataFrame:
# Since the function is labelled by the unique self._name, there's no need to include self in the arguments.
# Doing so would be ok but means also defining a __caching_id__ = self._name property for _Dataset so that
# Flask Caching does not fall back on __repr__ to identify the _Dataset instance, which is risky.
@self._cache.memoize(**self._cache_arguments)
@self._cache.memoize(timeout=self._timeout)
def _load_data():
logger.debug("Cache for dataset %s not found; reloading data", self._name)
return self.__load_data()
Expand Down

0 comments on commit a9b3894

Please sign in to comment.