Does ktor support forced caching?

248 views Asked by At

I have been using okhttp to access my server in the past. Okhttp supports caching very well and can force caching using the client's policy (rather than according to the server's caching policy).

This mechanism allowed the client to work normally even if the network was down at the time, as long as the configured cache expiration time (maxAge) was met, and the program was structured without any adjustments, as if it was accessed normally.

Even if the maxAge is exceeded, the program gets performance benefits due to the cache as long as it is within the maxStale time (reading the local cache and refreshing the cache are done in parallel).

With the gradual use of Kotlin, I would also like to try kotlin native support for ktor. But I found out in my usage that ktor does not support forced caching. It always goes to the server, gets the valid cache time of the object from the server side, and then determines whether to refresh the cache or not.

This mechanism must ensure that the network is always available, and if it is not, the program needs to handle it accordingly. This is not a very good solution for mobile applications.

I don't know if I didn't find the interface to set the client-side cache and didn't set it up properly. I wish I could just set up forced caching instead of going through the server every time to get the caching policy.

0

There are 0 answers