Single-node cache / practical evaluation

Cache a JSON API response with a TTL

Verify a short-lived JSON cache entry over RESP, read it back and check expiration before integrating a rebuildable cache into your application.

Updated October 27, 2026 · Preview scope · disposable data · documented RESP commands

A small cache is a useful first evaluation because its behavior is easy to check: a write succeeds, a read returns the same response and an expired entry becomes a miss. The application’s database or upstream API remains the source of truth. This guide uses synthetic data and a disposable key.

Prepare an isolated instance

Use a Spedo instance reachable on a private interface. Follow the deployment and authentication guide, configure a password and keep the RESP port off the public Internet. This example defaults to 127.0.0.1:6380. Set SPEDO_HOST and SPEDO_PORT if your isolated test instance uses another endpoint.

Set SPEDO_PASSWORD in your local environment to that instance’s credential. Do not commit it to application source, paste it into public reports or reuse a production secret for the example.

Install the example client

python3 -m pip install redis

The redis-py client speaks RESP. Using it here demonstrates the commands exercised by this example; it does not establish compatibility with every Redis command, client feature or deployment mode. Validate the exact client version and behavior your application needs.

Write, read and expire one JSON response

Save the following code as cache_example.py. The JSON document is stored as a string with a five-second expiration; this example does not require native JSON-path commands.

import json
import os
import time
import redis

cache = redis.Redis(
    host=os.environ.get("SPEDO_HOST", "127.0.0.1"),
    port=int(os.environ.get("SPEDO_PORT", "6380")),
    password=os.environ["SPEDO_PASSWORD"],
    decode_responses=True,
)
key = "guide:cache:product:42"
payload = {"id": 42, "name": "demo"}

assert cache.set(key, json.dumps(payload), ex=5)
assert json.loads(cache.get(key)) == payload
print("JSON round trip: OK")

time.sleep(6)
assert cache.get(key) is None
print("TTL expiry: OK")
python3 cache_example.py

The expected output is:

JSON round trip: OK
TTL expiry: OK

The test intentionally waits longer than the TTL. If an assertion fails, inspect authentication, the endpoint, the response and the client behavior. A successful connection alone is not a successful cache evaluation.

Turn the check into cache-aside behavior

On a cache hit, decode and return the stored response. On a miss, fetch the authoritative value, return it and cache a copy with an explicit TTL. Bound the entry size and choose the TTL from your freshness requirements. Decide how the application behaves if Spedo is unavailable; rebuildable cache state should not silently become the only copy of important data.

Use a clear key namespace and include the dimensions that change the result. For personalized or access-controlled responses, an incomplete cache key can return data to the wrong user. The synthetic public product record avoids that concern during the first evaluation.

Know what this proof covers

This small check establishes one JSON-string round trip and TTL expiry for the tested instance and client. It does not measure throughput, validate crash recovery, establish an SLA or prove distributed availability. Read the product scope and the single-node evaluation checklist before expanding the workload.

Try it on your own workload

Use a private, bounded instance with synthetic data. Keep the authoritative data source and validate the behavior your application requires.

Start a local evaluation →

Continue the investigation