mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.87k stars 579 forks source link

Documentation: Redis caching backend #1356

Open daberlin opened 1 year ago

daberlin commented 1 year ago

Hi. I'm using Redis as a caching backend for Zeep in a project of mine. Maybe it would be helpful for others to add the below (minimal) sample to the docs:

class ZeepRedisCache(zeep.cache.Base):
    redis = None
    expiry = None

    def __init__(self, redis_host: str, redis_db: int, expiry: int = 86400) -> None:
        self.redis = redis.Redis(host=redis_host, db=redis_db)
        self.expiry = expiry

    def add(self, url: str, content: bytes) -> None:
        self.redis.setex(url, self.expiry, content)

    def get(self, url: str) -> bytes | None:
        return self.redis.get(url)