response.headers.add('X-Script-Version', 'runtime-cache-1.0')

function del() {
    var script = payload.get().query['path[]']
    if (script[0] == '*') {
        runtime.cache.purge()
        return ``
    }
    for (var i = 0; i < script.length; i++) {
        runtime.cache.remove(script[i])
    }
}

function get() {
    var script = payload.get().query['path']
    if (!script || script == '' || script == '*') {
        return okMsg(runtime.cache.list())
    }
    return runtime.cache.get(script)
}

function main() {
    // 验证用户权限
    // 'use api/user/acl/excerpt.js'

    switch (payload.get().method) {
        case 'GET':
            return get()
        case 'DELETE':
            return del()
        default:
            response.status.notFound()
            return `404 page not found`
    }
}