An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# CoCache
Level 2 Distributed Coherence Cache Framework

[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![GitHub release](https://img.shields.io/github/release/Ahoo-Wang/CoCache.svg)](https://github.com/Ahoo-Wang/CoCache/releases)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.ahoo.cocache/cocache-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/me.ahoo.cocache/cocache-core)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a2f3fd9b1e564fa3a3b558d1dfaf2a34)](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)
[![codecov](https://codecov.io/gh/Ahoo-Wang/CoCache/branch/main/graph/badge.svg?token=NlFI44RCS4)](https://codecov.io/gh/Ahoo-Wang/CoCache)
![Integration Test Status](https://github.com/Ahoo-Wang/CoCache/actions/workflows/integration-test.yml/badge.svg)

## Architecture


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


CoCache-Get-Sequence-Diagram

## JoinCache `Get` Sequence Diagram


JoinCache-Get-Sequence-Diagram