MCPcopy Create free account
hub / github.com/RightNow-AI/rightnow-cli / get_cached_kernel

Method get_cached_kernel

rightnow_cli/cache.py:152–179  ·  view source on GitHub ↗

Retrieve a cached kernel if available.

(self, model_name: str, operation: str)

Source from the content-addressed store, hash-verified

150 return kernel_id
151
152 def get_cached_kernel(self, model_name: str, operation: str) -> Optional[Dict[str, Any]]:
153 """Retrieve a cached kernel if available."""
154 with sqlite3.connect(self.db_path) as conn:
155 cursor = conn.cursor()
156 cursor.execute("""
157 SELECT id, file_path FROM kernel_metadata
158 WHERE model_name = ? AND operation = ?
159 ORDER BY created_at DESC
160 LIMIT 1
161 """, (model_name, operation))
162
163 result = cursor.fetchone()
164 if result:
165 kernel_id, file_path = result
166 kernel_file = Path(file_path)
167
168 if kernel_file.exists():
169 cursor.execute("""
170 UPDATE kernel_metadata
171 SET last_used = ?
172 WHERE id = ?
173 """, (datetime.now().isoformat(), kernel_id))
174 conn.commit()
175
176 with open(kernel_file, 'rb') as f:
177 return pickle.load(f)
178
179 return None
180
181 def list_cached_kernels(self, model_name: Optional[str] = None) -> List[Dict[str, Any]]:
182 """List all cached kernels, optionally filtered by model."""

Calls 3

existsMethod · 0.80
executeMethod · 0.45
loadMethod · 0.45