Session: stale-while-revalidate — 2026-09-10

edge-cache · OpenCode · branch feat/swr · claude-sonnet-4-6 · 2026-09-10 10:15 · 1 msgs · 3 tools · 1 min read · updated 8 weeks ago

tools: Bash, Edit, Write
← edge-cache Download .md .txt .json
Tool calls
Bash Bash: 1 call (33.3%) 1 Edit Edit: 1 call (33.3%) 1 Write Write: 1 call (33.3%) 1
Token usage134.4K total
Input14.4K
Cache creation28.8K
Cache read86.4K
Output4.8K
Cache hit ratio67%· warming up

Project: edge-cache · Branch: feat/swr · Mode: default · Model: claude-sonnet-4-6

Summary

Implemented stale-while-revalidate in the Go caching proxy: stale entries are served immediately while a single background refresh per key runs under singleflight, so a hot key never stampedes the origin.

Conversation

Turn 1 — User

Add stale-while-revalidate. Origin must not get a thundering herd.

Turn 1 — Assistant

Serve stale within the SWR window, trigger one refresh per key through singleflight.Group, and cap refresh concurrency with a semaphore.

func (c *Cache) serve(w http.ResponseWriter, r *http.Request, key string) {
    entry, ok := c.store.Get(key)
    if ok && entry.Fresh(time.Now()) {
        entry.WriteTo(w)
        return
    }
    if ok && entry.WithinSWR(time.Now()) {
        entry.WriteTo(w) // serve stale now
        go c.group.Do(key, func() (any, error) { return c.refresh(key, r) })
        return
    }
    c.fetchAndStore(w, r, key)
}

Tools used in this turn:

  • Edit: cache/handler.go
  • Write: cache/refresh.go
  • Bash: go test ./... -race — ok

Connections

  • [[edge-cache]]
  • [[Go]]
  • [[Singleflight]]
  • [[StaleWhileRevalidate]]

Keyboard shortcuts

⌘K / Ctrl+KOpen command palette
/Focus search
g hGo to home
g pGo to projects
g sGo to sessions
j / kNext / prev row (tables)
?Show this help
EscClose dialogs

Structured queries

Mix key:value filters with free text in the palette:

type:sessionOnly session pages
project:llm-wikiFilter by project name (substring)
model:claudeFilter by model name (substring)
date:>2026-03-01Sessions after a date
date:<2026-04-01Sessions before a date
tags:rustPages mentioning a tag/topic
sort:dateSort results by date (newest first)

Example: type:session project:llm-wiki date:>2026-04 sort:date