{"id":23555289,"url":"https://github.com/tri5m/tutu-cache","last_synced_at":"2025-04-30T04:46:45.798Z","repository":{"id":41439964,"uuid":"318978363","full_name":"tri5m/tutu-cache","owner":"tri5m","description":"Tu-cache is a cache annotation tool based on Spring that can be quickly integrated and used to address the issue of insufficient flexibility with annotations like @Cacheable and @CacheEvict.","archived":false,"fork":false,"pushed_at":"2025-04-21T02:35:35.000Z","size":272,"stargazers_count":49,"open_issues_count":3,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-30T04:46:35.078Z","etag":null,"topics":["annotation-tool","cache","redis","spring-boot","spring-cache","spring-cache-redis","tu-cache"],"latest_commit_sha":null,"homepage":"https://doc.tucache.tunan.co","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tri5m.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-06T07:41:13.000Z","updated_at":"2025-04-28T03:28:24.000Z","dependencies_parsed_at":"2024-02-06T12:57:54.078Z","dependency_job_id":"a498af92-c4a9-450b-b45d-a68fe79f4dc7","html_url":"https://github.com/tri5m/tutu-cache","commit_stats":{"total_commits":83,"total_committers":2,"mean_commits":41.5,"dds":"0.15662650602409633","last_synced_commit":"536555e495ea8f3bbdb263ea1626c0a3fad1de7e"},"previous_names":["trifolium-x/tutu-cache","trifolium-wang/tutu-cache","tri5m/tutu-cache"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tri5m%2Ftutu-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tri5m%2Ftutu-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tri5m%2Ftutu-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tri5m%2Ftutu-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tri5m","download_url":"https://codeload.github.com/tri5m/tutu-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251644826,"owners_count":21620630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation-tool","cache","redis","spring-boot","spring-cache","spring-cache-redis","tu-cache"],"created_at":"2024-12-26T13:09:52.545Z","updated_at":"2025-04-30T04:46:45.784Z","avatar_url":"https://github.com/tri5m.png","language":"Java","readme":"![tu-cache](https://socialify.git.ci/tri5m/tutu-cache/image?font=Inter\u0026forks=1\u0026issues=1\u0026language=1\u0026name=1\u0026owner=1\u0026pattern=Plus\u0026stargazers=1\u0026theme=Auto)\ntutu-cache 是一个简单易用的Spring缓存注解。\n\u003cbr/\u003e\n使用tutu-cache注解来代替@Cacheable和@CacheEvict等注解\n\n[![GitHub license](https://img.shields.io/github/license/tri5m/tutu-cache)](https://github.com/tri5m/tutu-cache/blob/master/LICENSE)\n[![RELEASE](https://img.shields.io/badge/RELEASE-1.0.5-blue)](https://github.com/tri5m/tutu-cache/releases/tag/v1.0.5)\n\n### 🎉Version\n* 最新版本 1.0.5\n* 注意1.0.5以前的版本，groupId为co.tunan.tucache。\n* 几大亮点\n  1. 支持模糊删除缓存\n  2. 支持spEl表达式\n  3. 支持自定义缓存服务\n  4. 支持本地缓存\n  5. 配置简单，使用方便\n  \n### 🥳Quick Start\n1. 在springBoot中的使用\n    * 引入jar依赖包\n      ```xml\n      \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.github.tri5m\u003c/groupId\u003e\n            \u003cartifactId\u003etucache-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e1.0.5\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003c!-- 可选，建议使用redis,如有没redis依赖默认使用本地缓存 --\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n            \u003cartifactId\u003espring-boot-starter-data-redis\u003c/artifactId\u003e\n        \u003c/dependency\u003e\n      \u003c/dependencies\u003e\n      ```\n      \n### 😊使用tu-cache\n1. 使用tu-cache对service中的方法返回的数据进行缓存\n    ```java\n    @TuCache(\"test_service:getList\")\n    public List\u003cString\u003e getList(){\n        return Arrays.asList(\"tu\",\"nan\");\n    }\n    ```\n2. 使用tu-cache删除缓存中的数据\n    ```java\n    @TuCacheClear(\"test_service:getList\")\n    public void delList(){\n    }\n    ```\n3. @TuCache参数\n    * `String key() default \"\"` 缓存的字符串格式key,支持spEl表达式(使用#{}包裹spEl表达式)，默认值为方法签名\n    * `long timeout() default -1` 缓存的过期时间，单位(秒),默认永不过期. (在1.0.4.RELEASE以前版本中使用 `expire`)\n    * `boolean resetExpire() default false` 每次获取数据是否重置过期时间.\n    * `TimeUnit timeUnit() default TimeUnit.SECONDS` 缓存的时间单位.\n    * `String condition() default \"true\"` 扩展的条件过滤，值为spEl表达式(直接编写表达式不需要使用#{}方式声明为spEl)\n    * 样例:\n        ```java\n        @TuCache(key=\"test_service:getList:#{#endStr}\", timeout = 10, timeUnit=TimeUnit.SECONDS)\n        public List\u003cString\u003e getList(String endStr){\n            return Arrays.asList(\"tu\",\"nan\",endStr);\n        }\n        \n        // 如果需要当前对象的的方法\n        @TuCache(key=\"test_service:getList:#{#this.endStr()}\", timeout = 120)\n        public List\u003cString\u003e getList(){\n            return Arrays.asList(\"tu\",\"nan\",endStr());\n        }\n        \n        // 使用springBean, (使用安全访问符号?.，可以规避null错误，具体用法请查看spEl表达式)\n        @TuCache(key=\"test_service:getList:#{@springBean.endStr()}\", timeout = 120)\n        public List\u003cString\u003e springBeanGetList(){\n            return Arrays.asList(\"tu\",\"nan\",springBean.endStr());\n        }\n        \n        // 使用condition,当name的长度\u003e=5时进行缓存\n        @TuCache(key=\"test_service:getList:#{#name}\", condition=\"#name.length() \u003e= 5\")\n        public List\u003cString\u003e springBeanGetList(String name){\n            return Arrays.asList(\"tu\",\"nan\",name);\n        }\n        \n        public String endStr(){\n          return \"end\";\n        }\n        ```\n4. @TuCacheClear参数\n    * `String[] key() default {}` 删除的key数组，支持spEl表达式(使用#{}包裹spEl表达式)\n    * `String[] keys() default {}` 模糊删除的缓存key数组,支持spEl表达式(使用#{}包裹spEl表达式),对应redis中**deleteKeys**(\"test_service:\")\n    * `boolean async() default false` 是否异步删除，无需等待删除的结果\n    * `String condition() default \"true\"` 扩展的条件过滤，值为spEl表达式(直接编写表达式不需要使用#{}方式声明为spEl)\n    * 样例:\n        ```java\n        @TuCacheClear(key={\"test_service:itemDetail:#{#id}\"})\n        public void deleteItem(Long id){\n        }\n        \n        // 模糊删除 test_service:itemList:开头的所有key\n        @TuCacheClear(keys={\"test_service:itemList:\"}, async = true)\n        public void deleteItem(Long id){\n        }\n      \n        // 支持spEl表达式\n        @TuCacheClear(keys={\"test_service:itemList:\",\"test_service:itemDetail:#{#id}\"}, async = true)\n        public void deleteItem(Long id){\n        }\n        ```\n    * _注意key和keys的区别_\n5. condition 的用法\n    * condition要求spEL返回一个boolean类型的值，例如：\n      * condition = \"#param.startsWith('a')\"\n      * condition = \"false\"\n\n* 如果使用redisTemplate, 建议自定义序列化在Configure类中注册javaBean redisTemplate或者使用默认的redisTemplate，必须开启aspectj的aop功能(默认是开启的)\n  ```java\n  // 建议的redisTemplate序列化配置， 强烈建议使用对key使用String方式序列化\n  @Bean(name = \"redisTemplate\")\n    public RedisTemplate\u003cString, Object\u003e redisTemplate(RedisConnectionFactory redisConnectionFactory) {\n        RedisTemplate\u003cString, Object\u003e redisTemplate = new RedisTemplate\u003c\u003e();\n        redisTemplate.setKeySerializer(new StringRedisSerializer());\n        redisTemplate.setHashKeySerializer(new StringRedisSerializer());\n        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer(createGenericObjectMapper()));\n        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer(createGenericObjectMapper()));\n    \n        redisTemplate.setConnectionFactory(redisConnectionFactory);\n    \n        return redisTemplate;\n    }\n  ```\n### 😋个性化设置\n* **springBoot中配置**\n    ```yaml\n    tucache:\n      enabled: true\n      cache-type: redis\n      profiles:\n        cache-prefix: \"my_tu_key_test:\"\n        # ...\n    ```\n* 如果用户需要每个缓存前面添加同意的keyPrefix，TuCacheBean的prefixKey参数\n* 如果不指定cache-type，则会自动推断使用的缓存工具，优先级为 custom \u003e redis \u003e redisson \u003e local\n* tutu-cache默认提供了一下缓存服务\n  1. `RedisTuCacheService`\n  2. `RedissonTuCacheService`\n  3. `LocalTuCacheService`\n  4. 优先级从前往后\n  \n* 用户使用其他缓存，则需要自定义`TuCacheService`，并配置为spring bean\n    ```java\n     // 自定义缓存服务\n     @Primary\n     @Bean\n     public TuCacheService myCustomCacheService(){\n         return new MyCustomCacheService();\n     }\n    ```\n\n#### 作者QQ 交流群: 76131683\n#### 希望更多的开发者参与\n☕️[请我喝一杯咖啡]\n* ↓↓↓ 微信扫码 ↓↓↓\n\n\u003cimg src=\"assets/payee/wechat.jpg\" width=\"25%\" alt=\"赞赏码\"/\u003e\n\n### 打赏列表\n| 昵称(按时间顺序) | 金额 | 账号       |\n|-----------|----|----------|\n|  一直在梦想路上 | 20  | 20***154 |\n|           |    |          |\n|           |    |          |\n\n\n[//]: # (### [感谢JetBrains提供的免费授权]\u0026#40;https://www.jetbrains.com/?from=tutu-cache\u0026#41;)\n\n[//]: # ([![JetBrains logo]\u0026#40;assets/thanks/jetbrains.svg\u0026#41;]\u0026#40;https://www.jetbrains.com/?from=tutu-cache\u0026#41;)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftri5m%2Ftutu-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftri5m%2Ftutu-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftri5m%2Ftutu-cache/lists"}