show-me
Quoted exactly from the real run. Not edited.
# show-me real run
- Date: 2026-10-15 22:58 +0700
- Tool: Claude Code 2.1.300, headless `claude -p`, later turns with `--resume` (one session)
- Model: claude-sonnet-5-5
- Isolation: --setting-sources project --strict-mcp-config (no user skills, memory or MCP)
- Skill: humanlayer/skills @ 653b6411c1f70c275a18e37673b042ff99f67ceb `plugins/show-me/skills/show-me/SKILL.md` (MIT, HumanLayer)
- Exact first prompt: `/show-me How does a request to /menu flow through this app, and where does the cache sit?`
- User replies are sample text written by our team. Assistant text is verbatim from the session log. Tool calls are shown as one line notes; local paths in them are shortened to `~` and `<project>`.
## Turn 1
### User
/show-me How does a request to /menu flow through this app, and where does the cache sit?
> [event] skill loaded: show-me
> [tool call] Grep {"pattern": "menu|cache", "path": "<project>", "-i": true, "output_mode": "content", "glob": "!.claude/**", "head_limit": 80}
> [tool call] Glob {"pattern": "**/*", "path": "<project>"}
> [tool call] Read {"file_path": "<project>/src/server.js"}
> [tool call] Read {"file_path": "<project>/src/render.js"}
### Assistant
The cache is an in-memory object inside `getMenu()`, between the server and the file read. It lives in `src/menu.js:1`.
```text
GET /menu (src/server.js:5)
getMenu() (src/menu.js:3)
cache.items set and age < 60s? (src/menu.js:4)
yes -> return cache.items # cache hit, no disk read
no -> loadFromFile() # reads and parses src/menu.json
cache.items = result
cache.at = Date.now()
return cache.items
renderPage(items) (src/render.js:1) # builds <ul><li>name: price THB</li>…</ul>
res.end(html)
```
```mermaid
sequenceDiagram
participant C as Client
participant S as server.js
participant M as menu.js getMenu
participant K as cache {items, at}
participant F as menu.json
participant R as render.js
C->>S: GET /menu
S->>M: getMenu()
M->>K: fresh (<60s)?
alt hit
K-->>M: items
else miss or stale
M->>F: read + JSON.parse
F-->>M: items
M->>K: store items, at = now
end
M-->>S: items
S->>R: renderPage(items)
R-->>S: html
S-->>C: html
```
- **Cached data:** the cache holds the parsed menu items, not the rendered HTML. `renderPage` runs on every request.
- **Expiry:** the entry is stale after 60 seconds (TTL check at `src/menu.js:4`). Edits to `menu.json` can take up to a minute to show up.
- **Scope:** the cache is a module-level variable, so it exists per process. It isn't shared across processes and is lost on restart.
- **Concurrent misses:** several requests that arrive at once while the cache is empty or stale will each read the file, because nothing de-duplicates the loads.
- **Other URLs:** any path other than `/menu` returns 404 without touching the cache.
## Turn 2
### User
/show-me What would change if the cache held the rendered HTML instead of the menu items?
> [event] skill loaded: show-me
### Assistant
The cache would move up a layer: `getMenu()` would return HTML, and `renderPage` would run only on a miss.
```diff
GET /menu
- getMenu()
- cache fresh? -> items
- else loadFromFile() -> store items
- renderPage(items)
- res.end(html)
+ getMenuHtml()
+ cache fresh? -> html
+ else loadFromFile() -> renderPage(items) -> store html
+ res.end(html)
```
One way to write it:
```js
// src/menu.js
const { renderPage } = require('./render');
const cache = { html: null, at: 0 };
async function getMenuHtml() {
if (cache.html && Date.now() - cache.at < 60000) return cache.html;
cache.html = renderPage(await loadFromFile());
cache.at = Date.now();
return cache.html;
}
```
```js
// src/server.js
res.end(await getMenuHtml());
```
**Gains**
- A hit skips `renderPage`, which means no `map`/`join` and no string building per request. For a small menu the saving is tiny.
**Costs**
- **Coupling:** `menu.js` now imports `render.js`, so the data module knows about presentation.
- **Reuse:** the raw items are no longer available to other callers, such as a JSON endpoint or a different layout. Those would need their own cache or a second cache entry.
- **Cache key:** if rendering ever varies per request (language, currency, query params), you'd need one cache entry per variant. Today `renderPage` is a pure function of the items, so a single entry works.
- **Staleness:** the 60s TTL and the shared-per-process scope are unchanged. Render changes also show up only after the TTL or a restart.
For this app, caching items is the better fit. Rendering is cheap, and the cache stays reusable. Caching HTML only pays off if rendering becomes expensive or you serve the same page at high volume.