# 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 [![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)](https://github.com/Ahoo-Wang/CoCache) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Ahoo-Wang/CoCache) ## 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