コード例 #1
0
ファイル: cache.py プロジェクト: zaratec/picoCTF
def set(key, value, timeout=None, fast=False):
    """
    Set a key in the cache.

    Args:
        key: The cache key.
        timeout: Time the key is valid.
        fast: whether or not to use the fast cache
    """

    if fast:
        fast_cache[key] = {
            "result": value,
            "timeout": timeout,
            "set_time": time.time()
        }
        return


    db = api.common.get_conn()

    update = key.copy()
    update.update({"value":value})

    if timeout is not None:
        expireAt = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
        update.update({"expireAt": expireAt})

    db.cache.update(key, update, upsert=True)
コード例 #2
0
ファイル: cache.py プロジェクト: 2flying2/picoCTF-Platform-2
def set(key, value, timeout=None, fast=False):
    """
    Set a key in the cache.

    Args:
        key: The cache key.
        timeout: Time the key is valid.
        fast: whether or not to use the fast cache
    """

    if fast:
        fast_cache[key] = {
            "result": value,
            "timeout": timeout,
            "set_time": time.time()
        }
        return


    db = api.common.get_conn()

    update = key.copy()
    update.update({"value":value})

    if timeout is not None:
        expireAt = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
        update.update({"expireAt": expireAt})

    db.cache.update(key, update, upsert=True)
コード例 #3
0
ファイル: cache.py プロジェクト: seadog007/easyctf-2015
def set(key, value, timeout=120, fast=False):
	if fast:
		fast_cache[key] = {
			"result": value,
			"timeout": timeout,
			"set_time": time.time()
		}
		return
	
	db = api.common.db_conn()
	update = key.copy()
	update.update({ "value": value })
	
	if timeout is not None:
		expireAt = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
		update.update({ "expireAt": expireAt })
	
	db.cache.update(key, update, upsert=True)
コード例 #4
0
def _set(key, value, timeout=None):
    """
    Set a key in the cache.

    Args:
        key: The cache key
        timeout: Time the key is valid (seconds)
    """
    db = api.db.get_conn()
    cache_obj = {
        '$set': {
            'key': key,
            'value': value,
        }
    }

    if timeout is not None:
        cache_obj['$set']['expireAt'] = (datetime.datetime.now() +
                                         datetime.timedelta(seconds=timeout))
    db.cache.find_one_and_update({'key': key}, cache_obj, upsert=True)