MCPcopy
hub / github.com/marimo-team/marimo / cache_attempt

Method cache_attempt

marimo/_save/loaders/loader.py:120–150  ·  view source on GitHub ↗
(
        self,
        defs: set[Name],
        key: HashKey,
        stateful_refs: set[Name],
        glbls: dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

118 return Path(f"{prefix}{key.hash}")
119
120 def cache_attempt(
121 self,
122 defs: set[Name],
123 key: HashKey,
124 stateful_refs: set[Name],
125 glbls: dict[str, Any] | None = None,
126 ) -> Cache:
127 start_time = time.time()
128 loaded = self.load_cache(key, glbls=glbls)
129 if not loaded:
130 return Cache.empty(defs=defs, key=key, stateful_refs=stateful_refs)
131 load_time = time.time() - start_time
132
133 # TODO: Consider more robust verification
134 if loaded.hash != key.hash:
135 raise LoaderError("Hash mismatch in loaded cache.")
136 if (defs | stateful_refs) != set(loaded.defs):
137 raise LoaderError("Variable mismatch in loaded cache.")
138 self._hits += 1
139
140 # Track time savings: original runtime - time to load from cache
141 runtime = loaded.meta.get("runtime", 0)
142 if runtime > 0:
143 time_saved = runtime - load_time
144 self._time_saved += max(0, time_saved)
145
146 return Cache.new(
147 loaded=loaded,
148 key=key,
149 stateful_refs=stateful_refs,
150 )
151
152 @property
153 def hits(self) -> int:

Callers 3

cache_attempt_from_hashFunction · 0.80
test_cache_hit_missMethod · 0.80

Calls 5

load_cacheMethod · 0.95
LoaderErrorClass · 0.85
newMethod · 0.80
getMethod · 0.65
emptyMethod · 0.45

Tested by 1

test_cache_hit_missMethod · 0.64