guides

Redis and Caching

Cache compiled artifacts and results with Redis and Memcached.

Published May 30, 2026

Artifact Caching

Store compiled artifacts in Redis for shared access across workers:

import redis
import pickle

r = redis.Redis()

def get_cached_artifact(source_hash):
    data = r.get(f'pyvorin:artifact:{source_hash}')
    if data:
        return pickle.loads(data)
    return None

def cache_artifact(source_hash, artifact):
    r.setex(f'pyvorin:artifact:{source_hash}', 86400, pickle.dumps(artifact))

Result Caching

def cached_compute(key, data):
    cached = r.get(key)
    if cached:
        return cached
    result = compiled_compute(data)
    r.setex(key, 3600, result)
    return result

Cache Invalidation

r.delete('pyvorin:artifact:*')  # clear all artifact caches