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)
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)
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)