~sircmpwn/core.sr.ht

c19708ed878bb31f26673e6f232f55d9edd28ef1 — Drew DeVault a month ago f35f208 0.62.5
srht.cache: add generalized caching system
1 files changed, 22 insertions(+), 0 deletions(-)

A srht/cache.py
A srht/cache.py => srht/cache.py +22 -0
@@ 0,0 1,22 @@
"""
srht.cache is a simple wrapper around Redis which turns connection errors into
cache misses.
"""
from srht.redis import redis

def get_cache(key):
    try:
        return redis.get(key)
    except:
        return None

def set_cache(key, expr, value):
    try:
        redis.setex(key, expr, value)
    except:
        pass

def expunge_cache(key):
    """Failing to expunge the cache may be a security issue, so this is not
    wrapped in a try/except"""
    redis.delete(key)