'Flush all in memory key/values to database.'

@classmethod
def flush(cls, task=None):

    log.debug((u'Flushing    simple    persistence    for    task    %s    to    db.' % task))
    with Session() as session:
        for pluginname in cls.class_store[task]:
            for (key, value) in cls.class_store[task][pluginname].items():
                query = session.query(SimpleKeyValue).filter((SimpleKeyValue.task == task)).filter((SimpleKeyValue.plugin == pluginname)).filter((SimpleKeyValue.key == key))
                if (value == DELETE):
                    query.delete()
                else:
                    updated = query.update({u'value': newstr(json.dumps(value, encode_datetime=True))}, synchronize_session=False)
                    if (not updated):
                        session.add(SimpleKeyValue(task, pluginname, key, value))
