<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def trending(params):
 """gets trending content values """

    # get params
    try:
        series = params.get("site", [DEFAULT_SERIES])[0]
        offset = params.get("offset", [DEFAULT_GROUP_BY])[0]
        limit = params.get("limit", [20])[0]
    except Exception as e:
        LOGGER.exception(e)
        return json.dumps({"error": e.message}), "500 Internal Error"

    # check the cache
    cache_key = "{}:{}:{}:{}:{}".format(memcached_prefix, "trending.json", series, offset, limit)
    try:
        data = MEMCACHED_CLIENT.get(cache_key)
        if data:
            return data, "200 OK"
    except Exception as e:
        LOGGER.exception(e)

    # update series name
    series = update_trending_series(series)

    # parse the limit
    try:
        limit = int(limit)
    except ValueError:
        LOGGER.error("limit param must be an integer")
        return json.dumps({"error": "limit param must be an integer"}), "400 Bad Request"

    # build the query
    query = "SELECT content_id, sum(value) as value " \
            "FROM {series} " \
            "WHERE time > now() - {offset} " \
            "GROUP BY content_id;"
    args = {"series": series, "offset": offset}

    # send the request
    try:
        res = INFLUXDB_CLIENT.query(query.format(**args))

    # capture errors and send them back along with the query (for inspection/debugging)
    except Exception as e:
        LOGGER.exception(e)
        return json.dumps({"error": e.message, "query": query.format(**args)}), "500 Internal Error"

    # build the response object
    response = flatten_response(res)

    # limit the number of content per site
    for site, points in response.items():
        sorted_content = sorted(points, key=lambda p: p["value"], reverse=True)[:limit]
        response[site] = sorted_content

    clean_response = {}
    for site, values in response.items():
        clean_name = site.split("-")[0]
        clean_response[clean_name] = values
    res = json.dumps(clean_response)

    # cache the response
    try:
        MEMCACHED_CLIENT.set(cache_key, res, time=MEMCACHED_EXPIRATION)
    except Exception as e:
        LOGGER.exception(e)

    return res, "200 OK"