Scogun / ktor-simple-cache

Apache License 2.0
18 stars 1 forks source link

Ktor 3.0.0-beta-1 support #15

Closed Rattlyy closed 1 week ago

Rattlyy commented 7 months ago

title :) I'd be willing to work on a PR if needed.

Scogun commented 7 months ago

Hello @Rattlyy! I will check compatibility.

Scogun commented 7 months ago

Looks like there is no any problems with the plugin itself. However, TestApplicationEngine was changed and tests were affected. Will try to fix it asap.

kirk88 commented 5 months ago

Error in 3.0.0-beta-1

    routing {
        cacheOutput(2.seconds) {
            get("/short") {
                call.respond(Random.nextInt().toString())
            }
        }
        cacheOutput {
            get("/default") {
                call.respond(Random.nextInt().toString())
            }
        }
    }
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface io.ktor.server.routing.Route, but class was expected
    at com.ucasoft.ktor.simpleCache.CacheOutputKt.cacheOutput-hhJSO8g(CacheOutput.kt:13)
    at com.ucasoft.ktor.simpleCache.CacheOutputKt.cacheOutput-hhJSO8g$default(CacheOutput.kt:12)
    at com.example.plugins.HTTPKt.configureHTTP$lambda$15(HTTP.kt:88)
    at io.ktor.server.routing.RoutingKt.routing(Routing.kt:166)
    at com.example.plugins.HTTPKt.configureHTTP(HTTP.kt:87)
    at com.example.ApplicationKt.module(Application.kt:15)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
    at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
    at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:188)
    at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:111)
    at io.ktor.server.engine.internal.CallableUtilsKt.callFunctionWithInjection(CallableUtils.kt:120)
    at io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:36)
    at io.ktor.server.engine.EmbeddedServer$launchModuleByName$1.invoke(EmbeddedServerJvm.kt:349)
    at io.ktor.server.engine.EmbeddedServer$launchModuleByName$1.invoke(EmbeddedServerJvm.kt:348)
    at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartupFor(EmbeddedServerJvm.kt:373)
    at io.ktor.server.engine.EmbeddedServer.launchModuleByName(EmbeddedServerJvm.kt:348)
    at io.ktor.server.engine.EmbeddedServer.access$launchModuleByName(EmbeddedServerJvm.kt:27)
    at io.ktor.server.engine.EmbeddedServer$instantiateAndConfigureApplication$1.invoke(EmbeddedServerJvm.kt:336)
    at io.ktor.server.engine.EmbeddedServer$instantiateAndConfigureApplication$1.invoke(EmbeddedServerJvm.kt:327)
    at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartup(EmbeddedServerJvm.kt:355)
    at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication(EmbeddedServerJvm.kt:327)
    at io.ktor.server.engine.EmbeddedServer.createApplication(EmbeddedServerJvm.kt:142)
    at io.ktor.server.engine.EmbeddedServer.start(EmbeddedServerJvm.kt:270)
    at com.example.ApplicationKt.main(Application.kt:10)
    at com.example.ApplicationKt.main(Application.kt)
Scogun commented 5 months ago

So, it happens when you try to use Simple-Cache for 2.3.11 with 3.0.0-beta-1 Ktor. There is no issue if update the library up to Ktor 3.0.0-beta-1 too. However, I cannot find a good way for tests so far. But seems I will spend more time for it soon.

kirk88 commented 5 months ago

Thank you, this is because in version 2.3.11 Route is a class, but in 3.0.0-beta-1 it is an interface. I solved it temporarily by customizing the cacheOutput method.

SinonCute commented 1 week ago

How do you work around with this? I'm still experiencing this issue on 3.0.1

Scogun commented 1 week ago

Hello @SinonCute ,

I started to revrite tests. Should finish on this week.