📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-18-session-caching-redis-key-value.html

Deep dive 18 of 27: Session Caching (Redis/Key-Value)

Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ✅ built (SQLite, not Redis)

Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions

Part of: Remembering the right things: state management in NurseOps Now, section Implementing Long-Term Memory: External Persistence Architecture (7.3) · All 27 solutions · ← Semantic Storage (Vector DB like Pinecone, Weaviate, or Chroma) · The Rehydration Pattern →

Read in this order

  1. In plain words: what it is, without jargon
  2. The problem it solves: the problem, and the standard approach in my words
  3. How to implement it (ServiceApps): scenario, steps, code and real output
  4. In NurseOps Now: built or not, and where
  5. Trade-offs and Interview answer

In plain words

Session caching (saving a conversation's state so it can pause and resume) saves a conversation's whole state (everything the app must remember to continue correctly) (history and current step) under a session ID in a fast key-value store. If the user closes the browser and comes back, the session is loaded and the conversation continues.

In plain terms: a coat check: you get a ticket number, and your coat is waiting when you come back.

The problem it solves

Summarization solves volume, not time (a summary shrinks memory but doesn't survive a crash or restart): closing the tab or a server restart loses the conversation unless it's saved somewhere.

The standard approach (in my words): serialize the chat history and current state (everything the app must remember to continue correctly) into a JSON (a simple text format for structured data) blob stored by session ID (for example in Redis), enabling pause-and-resume and episodic recall.

How to implement it (ServiceApps)

Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.

The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.

The scenario. An employee is halfway through a VPN troubleshooting chat, closes the browser, and comes back later.

Steps.

  1. Pick a session ID (for example user + ticket).
  2. After each turn, save the state (everything the app must remember to continue correctly) as JSON (a simple text format for structured data) under that key, with an expiry.
  3. On return, load by session ID; start fresh if it's missing or expired.
  4. Clear the key when the conversation ends or the user asks.

The code (Python):

import json, time
class KV:                                        # stand-in for Redis: SET key value EX seconds / GET key
    def __init__(self): self.d = {}
    def set(self, k, v, ex=None): self.d[k] = (v, time.time() + ex if ex else None)
    def get(self, k):
        v, exp = self.d.get(k, (None, None))
        if exp and time.time() > exp:
            self.d.pop(k, None); return None
        return v

r = KV()
def save_session(sid, state): r.set(f"session:{sid}", json.dumps(state), ex=3600)
def load_session(sid):
    raw = r.get(f"session:{sid}")
    return json.loads(raw) if raw else {"history": [], "step": "start"}

sid = "u42:INC0012345"
s = load_session(sid); print("new session:", s)
s["history"] += ["user: VPN error 809", "assistant: are you on guest Wi-Fi?"]
s["step"] = "waiting_for_user"
save_session(sid, s)
print("browser closed ... user returns")
print("resumed    :", load_session(sid))

Output (from running the code above):

new session: {'history': [], 'step': 'start'}
browser closed ... user returns
resumed    : {'history': ['user: VPN error 809', 'assistant: are you on guest Wi-Fi?'], 'step': 'waiting_for_user'}

What to watch for.

In plain terms: the conversation is checked in under your ticket number and handed back when you return.

In NurseOps Now

Built with SQLite instead of Redis: LangGraph (a tool for building AI workflows step by step)'s SqliteSaver checkpoints (saved copies of a conversation's state) each AI Assist (the app's chat helper for staff questions) thread (one saved conversation, here one per user and case) (nurse1:case-3) after every step in assist_memory.db, and it survives restarts. Expiry isn't built yet (Plan 3). See Step 1.

Trade-offs

Interview answer

"Each conversation is saved under a session ID, user plus ticket, as a small JSON (a simple text format for structured data) state (everything the app must remember to continue correctly) with an expiry, after every turn. Closing the tab or restarting the server doesn't lose anything; the next message just reloads it."

All data in this post is made up. No real people, tickets or patient data.

← Back to all 27 solutions in the state management blog

Key terms

Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.

AI Assist
The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
checkpoints
Saved copies of a conversation's state.Used in: In NurseOps Now↩ Back to where you were
incident
A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
JSON
A simple text format for structured data.Used in: The problem it solves, How to implement it (ServiceApps), Interview answer↩ Back to where you were
KB
Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
LangGraph
A tool for building AI workflows step by step.Used in: In NurseOps Now↩ Back to where you were
sanitization layer
Code that masks personal details and secrets before anything is saved.Used in: How to implement it (ServiceApps)↩ Back to where you were
ServiceApps
A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
session caching
Saving a conversation's state so it can pause and resume.Used in: In plain words↩ Back to where you were
state
Everything the app must remember to continue correctly.Used in: In plain words, The problem it solves, How to implement it (ServiceApps), Interview answer↩ Back to where you were
summarization solves volume, not time
A summary shrinks memory but doesn't survive a crash or restart.Used in: The problem it solves↩ Back to where you were
thread
One saved conversation, here one per user and case.Used in: In NurseOps Now↩ Back to where you were