Kache icon indicating copy to clipboard operation
Kache copied to clipboard

how to use this?? property must be initialize or abstract

Open blackholeearth opened this issue 1 year ago • 1 comments

code:

package com.my.project
 
import com.mayakapps.kache.FileKache
import com.mayakapps.kache.KacheStrategy

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class AnilistQuery {

    val cache : FileKache  // error here...

    init {
        GlobalScope.launch (Dispatchers.Main)
        {
            val cache = FileKache(directory = "cache", maxSize = 10 * 1024 * 1024) {
                // Other optional configurations
                strategy = KacheStrategy.MRU
                // ...
            }
        }
    }


error: i am getting error: Property must be initialized or be abstract

how to use this??

blackholeearth avatar Nov 18 '24 09:11 blackholeearth

I guess you should initialize cache in a blocking way here (and Dispatchers.Main is the default anyway), so just use

class AnilistQuery {
    val cache = runBlocking {
        FileKache(directory = "cache", maxSize = 10 * 1024 * 1024) {
            // Other optional configurations
            strategy = KacheStrategy.MRU
            // ...
        }
    }
}

sschuberth avatar Apr 11 '25 15:04 sschuberth