# CoCache
**Repository Path**: AhooWang/CoCache
## Basic Information
- **Project Name**: CoCache
- **Description**: 分布式一致性二级缓存框架
- **Primary Language**: Kotlin
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: https://github.com/Ahoo-Wang/CoCache
- **GVP Project**: No
## Statistics
- **Stars**: 17
- **Forks**: 9
- **Created**: 2022-10-25
- **Last Updated**: 2025-07-05
## Categories & Tags
**Categories**: cache-modules
**Tags**: Redis, Kotlin, Java, Distributed, Cache
## README
# CoCache
Level 2 Distributed Coherence Cache Framework
[](https://www.apache.org/licenses/LICENSE-2.0.html)
[](https://github.com/Ahoo-Wang/CoCache/releases)
[](https://maven-badges.herokuapp.com/maven-central/me.ahoo.cocache/cocache-core)
[](https://www.codacy.com/gh/Ahoo-Wang/CoCache/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Ahoo-Wang/CoCache&utm_campaign=Badge_Grade)
[](https://codecov.io/gh/Ahoo-Wang/CoCache)
[](https://github.com/Ahoo-Wang/CoCache)
[](https://deepwiki.com/Ahoo-Wang/CoCache)
## Architecture
## Installation
> Use *Gradle(Kotlin)* to install dependencies
```kotlin
implementation("me.ahoo.cocache:cocache-spring-boot-starter")
```
> Use *Gradle(Groovy)* to install dependencies
```groovy
implementation 'me.ahoo.cocache:cocache-spring-boot-starter'
```
> Use *Maven* to install dependencies
```xml
me.ahoo.cocache
cocache-spring-boot-starter
${cocache.version}
```
## Usage
```mermaid
classDiagram
direction BT
class Cache~K, V~ {
<>
+ set(K, Long, V) Unit
+ getCache(K) CacheValue~V~?
+ set(K, Long, V) Unit
+ set(K, V) Unit
+ get(K) V?
+ set(K, V) Unit
+ get(K) V?
+ getTtlAt(K) Long?
+ setCache(K, CacheValue~V~) Unit
+ getTtlAt(K) Long?
+ evict(K) Unit
}
class CacheGetter~K, V~ {
<>
+ get(K) V?
}
class CacheSource~K, V~ {
<>
+ load(K) CacheValue~V~?
+ noOp() CacheSource~K, V~
}
class UserCache {
+ set(String, UserData) Unit
+ setCache(String, CacheValue~UserData~) Unit
+ getCache(String) CacheValue~UserData~?
+ evict(String) Unit
+ get(String) UserData?
+ getTtlAt(String) Long?
+ set(String, Long, UserData) Unit
}
class UserCacheSource {
+ load(String) CacheValue~UserData~?
}
Cache~K, V~ --> CacheGetter~K, V~
UserCache ..> Cache~K, V~
UserCacheSource ..> CacheSource~K, V~
```
```kotlin
/**
* 定义缓存接口
* 可选的配置
*/
@CoCache(keyPrefix = "user:", ttl = 120)
/**
* 可选的配置
*/
@GuavaCache(
maximumSize = 1000_000,
expireUnit = TimeUnit.SECONDS,
expireAfterAccess = 120
)
interface UserCache : Cache
@EnableCoCache(caches = [UserCache::class])
@SpringBootApplication
class AppServer
/**
* 可选的配置
*/
@Configuration
class UserCacheConfiguration {
@Bean
fun customizeUserClientSideCache(): ClientSideCache {
return MapClientSideCache()
}
@Bean
fun customizeUserCacheSource(): CacheSource {
return CacheSource.noOp()
}
}
```
## CoCache `Get` Sequence Diagram
## JoinCache `Get` Sequence Diagram