https://github.com/ahoo-wang/cocache
Level 2 Distributed Coherence Cache Framework
https://github.com/ahoo-wang/cocache
cache coherence distributed-cache java kotlin l2-cache microservice redis spring-boot
Last synced: about 1 month ago
JSON representation
Level 2 Distributed Coherence Cache Framework
- Host: GitHub
- URL: https://github.com/ahoo-wang/cocache
- Owner: Ahoo-Wang
- License: apache-2.0
- Created: 2022-02-19T12:44:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-04T23:30:49.000Z (about 1 month ago)
- Last Synced: 2025-05-07T13:06:19.253Z (about 1 month ago)
- Topics: cache, coherence, distributed-cache, java, kotlin, l2-cache, microservice, redis, spring-boot
- Homepage: https://deepwiki.com/Ahoo-Wang/CoCache/
- Size: 1.25 MB
- Stars: 11
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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)
## 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
![]()