Skip to content

buildKey() behavior in SimpleCachePlugin #21

@ShiinaKin

Description

@ShiinaKin

I have a question regarding the behavior of the buildKey method in SimpleCachePlugin.

private fun buildKey(request: ApplicationRequest, queryKeys: List<String>): String {
val keys =
if (queryKeys.isEmpty()) request.queryParameters else request.queryParameters.filter { key, _ -> key in queryKeys }
val key = "${request.path()}?${
keys.entries().sortedBy { it.key }
.joinToString("&") { "${it.key}=${it.value.sorted().joinToString(",")}" }
}"
return key.trimEnd('?')
}

According to the comment in the README:

Cache key will be built only on listed query keys. Others will be ignored!

However, I noticed that even when there are no query parameters, key is still generated. Is this the expected behavior?

I think that the request should only be cached if all the queryKeys are present in the query parameters. If any of the queryKeys isn't present, the request should not be cached.

sample ex:

cacheOutput(6.hours, listOf("id")) { route("random") { ... } }

cache result:

image

should only cache the one which take the id param

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions