# pop-cache **Repository Path**: billho/pop-cache ## Basic Information - **Project Name**: pop-cache - **Description**: PopCache 是一个 Spring Boot 启动器,提供基于 Redis 的缓存和分布式锁功能。它提供了一种简单灵活的方式将缓存和锁机制集成到 Spring Boot 应用中。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2025-02-08 - **Last Updated**: 2025-09-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: 缓存, Redis, Spring, SpringBoot ## README # PopCache - Redis-based Spring Boot Cache & Distributed Lock Solution PopCache is a Spring Boot starter that provides Redis-based caching and distributed lock capabilities. It offers a simple yet flexible way to integrate caching and locking mechanisms into Spring Boot applications. ## Features - **Annotation-based caching**: Easily manage cached data using `@Cache` and `@CacheClear` annotations - **Distributed global lock**: Implement distributed locks through `@GlobalLock` annotation - **Redis integration**: High-performance caching and locking based on Redis - **Custom key generation**: Extensible key generation strategies - **Serialization support**: Default JSON serialization with extensible options - **AOP implementation**: Separation of concerns through Aspect-Oriented Programming ## Modules ### Core Module - Defines core interfaces and implementations for caching and locking - Includes Redis-based implementations - Provides key generation and serialization utilities ### Annotation Module - Contains annotations for caching and locking: - `@Cache` - `@CacheClear` - `@GlobalLock` ### Starter Module - Spring Boot auto-configuration module - Provides out-of-the-box caching and locking capabilities - Includes property configuration support ## Quick Start 1. Add dependency to your project: ```xml cn.billho spring-boot-starter-pop-cache 1.1.0 ``` 2. Configure Redis connection in application.yml: ```yaml popcache: redis: host: localhost port: 6379 ``` 3. Use annotations in your code: ```java @Service public class MyService { @Cache(region = "user:{1}", key = "data", expire = 60) public String getCachedData(String userId) { // Business logic } @CacheClear(region = "user:{1}", key = "data") // If key is empty, deletes all keys under the region public void clearCache(String userId) { // Cache cleanup logic } @GlobalLock(key = "lock:{1}", timeout = 5000) public void performLockedOperation(String resourceId) { // Thread-safe operations } } ``` ## Configuration Properties ### Redis Connection (popcache.redis) | Property | Description | Default | |----------|-------------|---------| | host | Redis server address | Required | | port | Redis port | 6379 | | password | Redis authentication password | Empty | | timeout | Connection timeout (ms) | 2000 | | database | Database index | 1 | | enable | Enable Redis connection | false | ## Contributing We welcome contributions! Please follow these steps: 1. Fork the repository 2. Create your feature branch 3. Commit your changes 4. Push to the branch 5. Create a Pull Request ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.