~sircmpwn/core.sr.ht

core.sr.ht/srht/cache.py -rw-r--r-- 482 bytes
b695e020Drew DeVault Add "internal_anon" path for internal auth tokens 3 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)