I have a Kotlin object
with an inner map as cache. From my main thread, I load everything into the cache, if I print it, I get the filled map.
However when trying to get it from a Coroutine (in a Ktor route), the map is empty.
I've tried synchronized blocks over the map and my object, ConcurrentHashMap, Collections.synchronizedMap, kotlin mutexes, but nothing seems to work. I can't get rid of my coroutines and would like to keep this cache as it have a very large load on my server to fetch data from disk every try
After further investigation and testing, it appears that object
are not shared between class loaders.
Since Ktor is overriding the class loader for everything related to it (routes, calls, etc...), my class was not shared.
A solution is to ensure calls are always made from a ktor context which is, from within a ktor triggered function