KacheController

class KacheController(val cacheEnabled: () -> Boolean = { true }, client: RedisCoroutinesCommands<String, String>)

Constructors

Link copied to clipboard
constructor(cacheEnabled: () -> Boolean = { true }, client: RedisCoroutinesCommands<String, String>)

Properties

Link copied to clipboard

will be checked before checking cache, you can change this to false at anytime if you don't want to hit the cache

Functions

Link copied to clipboard
fun <T : Model> MongoCollection<T>.cacheKey(): String
Link copied to clipboard
suspend fun <T : Model> get(id: String, collection: MongoCollection<T>, serializer: KSerializer<T>, getData: suspend MongoCollection<T>.() -> T?): T?

Get A single item from your db or cache

Link copied to clipboard
suspend fun <T : Model> getAll(collection: MongoCollection<T>, serializer: KSerializer<T>, cacheKey: String = collection.cacheKey(), getData: suspend MongoCollection<T>.() -> List<T>): List<T>

Get the items from the list if they exist else perform the real query update the cache and return the results

Link copied to clipboard
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

Link copied to clipboard
suspend fun <T : Model> remove(id: String, collection: MongoCollection<T>, deleteData: suspend MongoCollection<T>.() -> Boolean): Boolean

Delete an item from your db, if that was successful return true or false if true the item is also deleted from the cache

Link copied to clipboard
suspend fun <T : Model> removeAll(collection: MongoCollection<T>, deleteData: suspend MongoCollection<T>.() -> Boolean): Boolean

Delete all the items in a collection, if that was successful return true or false if true all the items in the cache will also be deleted e.g

Link copied to clipboard
suspend fun <T : Model> set(collection: MongoCollection<T>, serializer: KSerializer<T>, setData: suspend MongoCollection<T>.() -> T?): T?

Insert or update a single item in your db and return it. This will update the item in the cache by the id

Link copied to clipboard
suspend fun <T : Model> setAll(collection: MongoCollection<T>, serializer: KSerializer<T>, cacheKey: String = collection.cacheKey(), setData: suspend MongoCollection<T>.() -> List<T>?): Boolean

Insert or update multiple items in your db and return the updated items. This will update their data in the cache buy their id

Link copied to clipboard
fun <T : Model> MongoCollection<T>.volatileCashKey(): String