Ecosyste.ms: Awesome
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: 15 days 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 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T21:35:57.000Z (24 days ago)
- Last Synced: 2024-10-26T11:18:15.107Z (22 days ago)
- Topics: cache, coherence, distributed-cache, java, kotlin, l2-cache, microservice, redis, spring-boot
- Homepage:
- Size: 878 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
## 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
class UserCache(private val delegate: Cache) :
Cache by delegate@AutoConfiguration
class UserCacheAutoConfiguration {
companion object {
const val CACHE_KEY_PREFIX = "iam"
const val USER_CACHE_BEAN_NAME = "userCache"
const val USER_CACHE_SOURCE_BEAN_NAME = "${USER_CACHE_BEAN_NAME}Source"
}@Bean
@ConditionalOnMissingBean(name = [USER_CACHE_SOURCE_BEAN_NAME])
fun userCacheSource(userClient: UserClient): CacheSource {
return UserCacheSource(userClient)
}@Bean
@ConditionalOnMissingBean
fun userCache(
@Qualifier(USER_CACHE_SOURCE_BEAN_NAME) cacheSource: CacheSource,
redisTemplate: StringRedisTemplate,
cacheManager: CacheManager,
clientIdGenerator: ClientIdGenerator
): UserCache {
val clientId = clientIdGenerator.generate()
val cacheKeyPrefix = "$CACHE_KEY_PREFIX:user:"
val codecExecutor = ObjectToJsonCodecExecutor(UserData::class.java, redisTemplate, JsonSerializer)
val distributedCaching: DistributedCache = RedisDistributedCache(redisTemplate, codecExecutor)
val delegate = cacheManager.getOrCreateCache(
CacheConfig(
cacheName = USER_CACHE_BEAN_NAME,
clientId = clientId,
keyConverter = ToStringKeyConverter(cacheKeyPrefix),
distributedCaching = distributedCaching,
cacheSource = cacheSource,
),
)
return UserCache(delegate)
}
}
```## CoCache `Get` Sequence Diagram
## JoinCache `Get` Sequence Diagram