wrapper around :func:`create_highlights` that stores the response
    payload in the `kvlayer` table called `highlights` as a stored
    value if data['store'] is `False`.  This allows error values as
    well as successful responses from :func:`create_highlights` to
    both get stored.

def maybe_store_highlights(file_id, data, tfidf, kvlclient):
    '''wrapper around :func:`create_highlights` that stores the response
    payload in the `kvlayer` table called `highlights` as a stored
    value if data['store'] is `False`.  This allows error values as
    well as successful responses from :func:`create_highlights` to
    both get stored.

    '''
    payload = create_highlights(data, tfidf)
    if data['store'] is True:
        stored_payload = {}
        stored_payload.update(payload)
        stored_payload['state'] = STORED
        payload_str = json.dumps(stored_payload)
        kvlclient.put('highlights', (file_id, payload_str))
    return payload