Platform 06 · Study guide
Store temporary values in memory, on disk, or Redis — and clear them from the CLI.
from tpy.cache import Cache, MemoryStore, FileStore
# Process memory (fast, lost on restart)
cache = Cache(MemoryStore())
# Shared file cache for local multi-process demos
cache = Cache(FileStore("storage/framework/cache"))
cache.put("user:1", {"name": "Asha"}, ttl=60)
user = cache.get("user:1")
cache.forget("user:1")
$ tpy cache clear
$ pip install "tamilPY[redis]"
from tpy.cache import Cache, RedisStore cache = Cache(RedisStore(url="redis://localhost:6379/0"))
Cache is a small facade over a CacheStore.put writes a value with optional TTL seconds.get returns the value or a default if missing/expired.tpy cache clear flushes the configured/default stores used by the project.| Store | Use when |
|---|---|
| Memory | Single process, tests, tiny TTL data |
| File | Local persistence without Redis |
| Redis | Multi-server production cache |