Session Cache API¶
This page documents the session cache classes responsible for storing and retrieving Lean proof states and environments.
Session cache is used internally by the AutoLeanServer
class.
It enables efficient resumption of proofs and environments after server restarts, timeouts, and automated recover from crashes. While by default AutoLeanServer
instantiates a fresh PickleSessionCache
instance, you can also use a custom one. It can be useful to share a session cache between multiple AutoLeanServer
instances, or to use a custom session cache implementation.
from lean_interact.sessioncache import PickleSessionCache
from lean_interact.server import AutoLeanServer
# Create a session cache
cache = PickleSessionCache(working_dir="./cache")
# Create a Lean server with the cache
server = AutoLeanServer(config=..., session_cache=cache)
Session State Classes¶
SessionState¶
lean_interact.sessioncache.SessionState
dataclass
¶
PickleSessionState¶
lean_interact.sessioncache.PickleSessionState
dataclass
¶
Cache Implementation¶
BaseSessionCache¶
lean_interact.sessioncache.BaseSessionCache
¶
Bases: ABC
Source code in lean_interact/sessioncache.py
__init__()
abstractmethod
¶
add(lean_server, request, response, verbose=False)
abstractmethod
¶
Add a new item into the session cache. Args: lean_server: The Lean server to use. request: The request to send to the Lean server. response: The response from the Lean server. verbose: Whether to print verbose output. Returns: An identifier session_state_id, that can be used to access or remove the item.
Source code in lean_interact/sessioncache.py
is_empty()
abstractmethod
¶
keys()
abstractmethod
¶
Get all keys (session state IDs) currently in the cache.
Returns:
Type | Description |
---|---|
list[int]
|
A list of all session state IDs. |
reload(lean_server, timeout_per_state, verbose=False)
abstractmethod
¶
Reload the session cache. This is useful when the Lean server has been restarted and the session cache needs to be reloaded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lean_server
|
The Lean server to use. |
required | |
timeout_per_state
|
int | float | None
|
The timeout for each state in seconds. |
required |
verbose
|
bool
|
Whether to print verbose output. |
False
|
Source code in lean_interact/sessioncache.py
remove(session_state_id, verbose=False)
abstractmethod
¶
Remove an item from the session cache. Args: session_state_id: The identifier of the item to remove. verbose: Whether to print verbose output.
Source code in lean_interact/sessioncache.py
PickleSessionCache¶
lean_interact.sessioncache.PickleSessionCache
¶
Bases: BaseSessionCache
A session cache based on the local file storage and the REPL pickle feature.
Will maintain a separate session cache per server.
Source code in lean_interact/sessioncache.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
reload(lean_server, timeout_per_state, verbose=False)
¶
Reload the session cache. This method should be called only after a restart of the Lean REPL.