Cache

abstract class Cache : ICache, CacheProvider

缓存基类

内置实现 Cache的子类主要有以下几个:

MMKVCache:基于 MMKV 实现的键值对缓存

DataStoreCache:基于 DataStore 实现的键值对缓存

SharedPreferencesCache:基于 SharedPreferences 实现的键值对缓存

MemoryCache:基于 Map 实现的键值对缓存;主要应用场景:只需使用内存进行缓存即可满足需求;如:单元测试

Author

Jenly

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
abstract fun clear()

清空所有缓存的键值对

Link copied to clipboard
abstract fun getBoolean(key: String, defValue: Boolean): Boolean

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getByteArray(key: String, defValue: ByteArray?): ByteArray?

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getDouble(key: String, defValue: Double): Double

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getFloat(key: String, defValue: Float): Float

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getInt(key: String, defValue: Int): Int

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getLong(key: String, defValue: Long): Long

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun <T : Parcelable> getParcelable(key: String, tClass: Class<T>): T?

根据 key 获取缓存的值,如果未获取到,则返回空

abstract fun <T : Parcelable> getParcelable(key: String, tClass: Class<T>, defValue: T?): T?

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
open override fun getProvider(): String

获取缓存提供者

Link copied to clipboard
abstract fun getString(key: String, defValue: String?): String?

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun getStringSet(key: String, defValue: Set<String>?): Set<String>?

根据 key 获取缓存的值,如果未获取到,则返回默认值 defValue

Link copied to clipboard
abstract fun put(key: String, value: Parcelable?)
abstract fun put(key: String, value: Boolean?)
abstract fun put(key: String, value: ByteArray?)
abstract fun put(key: String, value: Double?)
abstract fun put(key: String, value: Float?)
abstract fun put(key: String, value: Int?)
abstract fun put(key: String, value: Long?)
abstract fun put(key: String, value: String?)
abstract fun put(key: String, value: Set<String>?)

根据 keyvalue 存放到缓存

Link copied to clipboard
abstract fun remove(key: String)

根据 key 删除缓存的键值对