MCPcopy Create free account
hub / github.com/karpathy/reader3 / load_book_cached

Function load_book_cached

server.py:20–35  ·  view source on GitHub ↗

Loads the book from the pickle file. Cached so we don't re-read the disk on every click.

(folder_name: str)

Source from the content-addressed store, hash-verified

18
19@lru_cache(maxsize=10)
20def load_book_cached(folder_name: str) -> Optional[Book]:
21 """
22 Loads the book from the pickle file.
23 Cached so we don't re-read the disk on every click.
24 """
25 file_path = os.path.join(BOOKS_DIR, folder_name, "book.pkl")
26 if not os.path.exists(file_path):
27 return None
28
29 try:
30 with open(file_path, "rb") as f:
31 book = pickle.load(f)
32 return book
33 except Exception as e:
34 print(f"Error loading book {folder_name}: {e}")
35 return None
36
37@app.get("/", response_class=HTMLResponse)
38async def library_view(request: Request):

Callers 2

library_viewFunction · 0.85
read_chapterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected