getVolatile

suspend fun <T : Model, R : Any> getVolatile(fieldName: String, collection: MongoCollection<T>, serializer: KSerializer<R>, setData: suspend MongoCollection<T>.() -> R): R

Volatiles are queries whose result depends on the state of the collection i.e if an items is added, modified or deleted it'll affect the response of the query e.g

val key = "${keyPrefix}page:$page|size:$size"
val results = cacheController.getVolatile(
key,
collection,
serializer = ListSerializer(elementSerializer = serializer)
) {
val skip = (page - 1) * size
val list = arrayListOf<T>()
list.addAll(getResults(skip).toList())
list
}
val countKey = "${keyPrefix}pagesCount|size:$size"
val totalItems = cacheController.getVolatile(
countKey,
collection,
serializer = Long.serializer()
) {
collection.estimatedDocumentCount().awaitFirst()
}