CoCache 是分布式一致性二级缓存框架。
Architecture
Installation
Use Gradle(Kotlin) to install dependencies
implementation("me.ahoo.cocache:cocache-spring-boot-starter")
Use Gradle(Groovy) to install dependencies
implementation 'me.ahoo.cocache:cocache-spring-boot-starter'
Use Maven to install dependencies
<dependency>
<groupId>me.ahoo.cocache</groupId>
<artifactId>cocache-spring-boot-starter</artifactId>
<version>${cocache.version}</version>
</dependency>
Usage
/**
* 定义缓存接口
* 可选的配置
*/
@CoCache
/**
* 可选的配置
*/
@GuavaCache(
maximumSize = 1000_000,
expireUnit = TimeUnit.SECONDS,
expireAfterAccess = 120
)
/**
* 可选的配置
*/
@MissingGuardCache(ttlSeconds = 120)
interface UserCache : Cache<String, User>
@EnableCoCache(caches = [UserCache::class])
@SpringBootApplication
class AppServer
/**
* 可选的配置
*/
@Configuration
class UserCacheConfiguration {
@Bean
fun customizeUserClientSideCache(): ClientSideCache<User> {
return MapClientSideCache()
}
@Bean
fun customizeUserCacheSource(): CacheSource<String, User> {
return CacheSource.noOp()
}
}
评论