Cache interface options #2653
Replies: 4 comments 10 replies
-
@andrewhill157 , thanks for opening this discussion and so sorry for the late response. You're correct that we have an API asymmetry between
I see the appeal of having the same interface for both. cc @dmadisetti — is that something that could be possible in the future? Separately — Andrew, I'm curious if you've gotten a chance to use our caching features, and if you had any feedback |
Beta Was this translation helpful? Give feedback.
-
@akshayka sorry for the late reply -- I've only used them in some simple test examples so not sure I have much feedback at this point other than the interface detail and some downstream limitations (or user error). For example, in my case the function I want to cache is called within another function, which doesn't seem to play nice with marimo's implementation currently -- for example:
yields a BlockException I also tried to make my own decorator but run into the same error when doing so. I don't currently have particular requirements re: save formats (pickle is fine for current use case), but like the idea of maintaining a generic (or auto) default personally. |
Beta Was this translation helpful? Give feedback.
-
As a general meta-note, I think would be nice to have a clearer conceptual picture about what we want from the notebook source files. Not just for developers, but more generally for users of marimo, and documented. One simple distinction from Jupyter is already obvious from the system premise, that is, in virtue of being I don't think this is an easy question. There are good arguments that could be made for each option. This question also interplays with another important API design dimension, namely the question of timeliness of cells (what does it mean for cells to have a time parameter, e.g. defaulting to now() but could be pegged for illustration?), and which is also an important deployment concern, if cells to be deployed in a kind of data processing DAG or executed at certain intervals. |
Beta Was this translation helpful? Give feedback.
-
Few thoughts:
So, maybe create App can be configured with Cacher (which in turn can be configured with different formats), and then there is
|
Beta Was this translation helpful? Give feedback.
-
I was looking more closely into the cache options added recently and saw that you'd added
mo.cache
andmo.persistent_cache
! Sorry if this overlaps with past discussion that I've missed somewhere!My understanding is that the former is used like
whereas the latter can be used like:
but can't be used to decorate functions and the docs point you to use of
@mo.cache
for that.In looking around at other options I came across joblib.Memory which can be used to decorate functions like
@mo.cache
(or the various functools cache options) like:but with a persistent cache.
I don't think you can directly use it as a context manager but you could obvs make something to do that pretty easily.
One thing I liked about this was that it keeps the interface when using a cache vs. a persistent cache very similar. Not sure if you would (or already have) consider anything like this as an alternative or extension of the ways marimo currently supports caching.
joblib.Memory
works fine for my purposes if decorating a function defined in a module outside of a notebook, but it doesn't seem to persistently cache if the function is defined inside the notebook. Seems like that is probably a known issue:joblib/joblib#1498
Beta Was this translation helpful? Give feedback.
All reactions