async def get_user(self, token):
        cache_key = self.get_user_cache_key(token['id'])
        store = cache.get_memory_cache()
        try:
            return store[cache_key]
        except KeyError:
            pass

        user_id = token.get('id')
        if user_id is None:
            return

        user_data = await utils.find_user(username=user_id)

        user = GuillotinaUser(user_id=user_data['username'],
                              properties=user_data['data'])
        user.password = user_data['password']
        # in oauth context, user can choose to only grant subset of all
        # available. In this context, we give them access to everything
        # on the container
        self.apply_scope(
            user, {
                'allowed_scopes': user_data['allowed_scopes'],
                'scope': user_data['allowed_scopes'],
            })
        store[cache_key] = user
        return user
Esempio n. 2
0
async def clear(context, request):
    memory_cache = cache.get_memory_cache()
    memory_cache.clear()
    pool = await cache.get_redis_pool()
    conn = await pool.acquire()
    await conn.flushall()
    pool.release(conn)
    return {'success': True}
Esempio n. 3
0
    def __init__(self, transaction, loop=None):
        super().__init__(transaction)
        self._loop = loop

        self._conn = None
        self._redis = None
        self._memory_cache = cache.get_memory_cache()
        self._settings = app_settings.get('redis', {})

        self._keys_to_publish = []

        self._stored_objects = []
Esempio n. 4
0
async def stats(context, request):
    memory_cache = cache.get_memory_cache()

    redis = aioredis.Redis(await cache.get_redis_pool())
    redis_data = await redis.info()
    return {
        'in-memory': {
            'size': len(memory_cache),
            'stats': memory_cache.get_stats()
        },
        'redis': redis_data
    }
Esempio n. 5
0
    async def invalidate(self, data):
        assert isinstance(data, dict)
        assert 'tid' in data
        assert 'keys' in data
        if data['tid'] in self._ignored_tids:
            # on the same thread, ignore this sucker...
            self._ignored_tids.remove(data['tid'])
            return

        mem_cache = cache.get_memory_cache()
        for key in data['keys']:
            if key in mem_cache:
                del mem_cache[key]

        for cache_key, ob in data.get('push', {}).items():
            mem_cache[cache_key] = ob
Esempio n. 6
0
async def clear(context, request):
    memory_cache = cache.get_memory_cache()
    memory_cache.clear()
    redis = aioredis.Redis(await cache.get_redis_pool())
    await redis.flushall()
    return {'success': True}