From 192f66a5c178eaa5a8d172075c58d61ebf69390c Mon Sep 17 00:00:00 2001 From: xiongchun <18616786188@qq.com> Date: Fri, 17 Dec 2021 15:13:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=A1=86=E6=9E=B6=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=EF=BC=8C=E5=B0=81=E8=A3=85=E7=BC=93=E5=AD=98starter?= =?UTF-8?q?=EF=BC=9Apangu-framework-cache-spring-boot-starter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pangu-examples/README.md | 5 +- ...ava => LayeringCachePanguApplication.java} | 4 +- .../main/resources/application-dev.properties | 7 --- .../pangu-examples-cache-single/.gitignore | 26 ++++++++++ .../pangu-examples-cache-single/README.md | 5 ++ .../pangu-examples-cache-single/pom.xml | 49 +++++++++++++++++++ .../single/SimpleCachePanguApplication.java | 35 +++++++++++++ .../showcases/cache/single/pojo/UserVO.java | 43 ++++++++++++++++ .../single/service/ApiBasedDemoService.java | 30 ++++++++++++ .../main/resources/application-dev.properties | 26 ++++++++++ .../src/main/resources/application.properties | 17 +++++++ .../service/ApiBasedDemoServiceTest.java | 21 ++++++++ pangu-examples/pom.xml | 1 + 13 files changed, 259 insertions(+), 10 deletions(-) rename pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/{CachePanguApplication.java => LayeringCachePanguApplication.java} (90%) create mode 100644 pangu-examples/pangu-examples-cache-single/.gitignore create mode 100644 pangu-examples/pangu-examples-cache-single/README.md create mode 100644 pangu-examples/pangu-examples-cache-single/pom.xml create mode 100644 pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/SimpleCachePanguApplication.java create mode 100644 pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/pojo/UserVO.java create mode 100644 pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoService.java create mode 100644 pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties create mode 100644 pangu-examples/pangu-examples-cache-single/src/main/resources/application.properties create mode 100644 pangu-examples/pangu-examples-cache-single/src/test/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoServiceTest.java diff --git a/pangu-examples/README.md b/pangu-examples/README.md index 39e7a004f..48338f0cd 100644 --- a/pangu-examples/README.md +++ b/pangu-examples/README.md @@ -24,7 +24,10 @@ 3. 分页查询和手工映复杂SQL的方法 - **pangu-examples-cache-layering** - 1. 如何使用两级缓存(本地缓存+Redis集中缓存)。 + 1. 如何使用两级缓存(本地缓存+Redis集中缓存) + +- **pangu-examples-cache-layering** + 1. 如何使用原生的一级缓存RedisTemplate API - **pangu-examples-dubbo-api** 1. 开发Dubbo服务时接口文件和POJO相关类的打包模块 diff --git a/pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/CachePanguApplication.java b/pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/LayeringCachePanguApplication.java similarity index 90% rename from pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/CachePanguApplication.java rename to pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/LayeringCachePanguApplication.java index 41a1b0c5a..71d2f0fd2 100644 --- a/pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/CachePanguApplication.java +++ b/pangu-examples/pangu-examples-cache-layering/src/main/java/com/gitee/pulanos/pangu/showcases/cache/layering/LayeringCachePanguApplication.java @@ -28,10 +28,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @Slf4j @EnableLayeringCache @SpringBootApplication -public class CachePanguApplication { +public class LayeringCachePanguApplication { public static void main(String[] args) { - PanGuApplicationBuilder.init(CachePanguApplication.class).run(args); + PanGuApplicationBuilder.init(LayeringCachePanguApplication.class).run(args); } } \ No newline at end of file diff --git a/pangu-examples/pangu-examples-cache-layering/src/main/resources/application-dev.properties b/pangu-examples/pangu-examples-cache-layering/src/main/resources/application-dev.properties index b4591dcd6..4c112443f 100644 --- a/pangu-examples/pangu-examples-cache-layering/src/main/resources/application-dev.properties +++ b/pangu-examples/pangu-examples-cache-layering/src/main/resources/application-dev.properties @@ -16,13 +16,6 @@ # spring.application.name=pangu-examples-cache-layering -# spring-cache \u4E00\u7EA7\u7F13\u5B58 -spring.redis.host=localhost -spring.redis.database=1 -spring.redis.port=6379 -spring.redis.password= - - # layering-cache \u591A\u7EA7\u7F13\u5B58 # \u7F13\u5B58\u76D1\u63A7\u7EDF\u8BA1\u5F00\u5173 \u7F3A\u7701true layering-cache.stats=false diff --git a/pangu-examples/pangu-examples-cache-single/.gitignore b/pangu-examples/pangu-examples-cache-single/.gitignore new file mode 100644 index 000000000..c28c61a9c --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/.gitignore @@ -0,0 +1,26 @@ +/target/ +/bin/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ diff --git a/pangu-examples/pangu-examples-cache-single/README.md b/pangu-examples/pangu-examples-cache-single/README.md new file mode 100644 index 000000000..c33ec2321 --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/README.md @@ -0,0 +1,5 @@ +#### :mushroom: 本范例演示功能 + +1. 如何使用原生的一级缓存RedisTemplate API。 + +**更多开发指南请参考盘古平台相关文档说明。** \ No newline at end of file diff --git a/pangu-examples/pangu-examples-cache-single/pom.xml b/pangu-examples/pangu-examples-cache-single/pom.xml new file mode 100644 index 000000000..9b87dc563 --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + com.gitee.pulanos.pangu + pangu-parent + 5.0.7 + + + + com.gitee.pulanos.pangu + pangu-examples-cache-single + jar + 1.0.0 + + + + com.gitee.pulanos.pangu + pangu-spring-boot-starter + + + com.gitee.pulanos.pangu + pangu-cache-spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + diff --git a/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/SimpleCachePanguApplication.java b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/SimpleCachePanguApplication.java new file mode 100644 index 000000000..b2645ebe0 --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/SimpleCachePanguApplication.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.gitee.pulanos.pangu.showcases.cache.single; + +import com.gitee.pulanos.pangu.framework.starter.PanGuApplicationBuilder; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author xiongchun + */ +@Slf4j +@SpringBootApplication +public class SimpleCachePanguApplication { + + public static void main(String[] args) { + PanGuApplicationBuilder.init(SimpleCachePanguApplication.class).run(args); + } + +} \ No newline at end of file diff --git a/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/pojo/UserVO.java b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/pojo/UserVO.java new file mode 100644 index 000000000..2c87d42fb --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/pojo/UserVO.java @@ -0,0 +1,43 @@ +package com.gitee.pulanos.pangu.showcases.cache.single.pojo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author xiongchun + */ +@Data +@Accessors(chain = true) +public class UserVO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 流水号 + */ + private Long id; + + /** + * 姓名 + */ + private String name; + + /** + * 生日 + */ + private Date birthday; + + /** + * 年龄 + */ + private Integer age; + + /** + * 创建时间 + */ + private Date gmtCreate; + +} diff --git a/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoService.java b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoService.java new file mode 100644 index 000000000..aa089a170 --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/main/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoService.java @@ -0,0 +1,30 @@ +package com.gitee.pulanos.pangu.showcases.cache.single.service; + +import com.alibaba.fastjson.JSON; +import com.gitee.pulanos.pangu.showcases.cache.single.pojo.UserVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +/** + * 基于API的一级缓存演示 + * + * @author xiongchun + */ +@Slf4j +@Component +public class ApiBasedDemoService { + + @Autowired + private RedisTemplate redisTemplate; + + public void testRedisCache() { + String key = "user:1"; + UserVO userVO = new UserVO().setId(1L).setName("钱学森"); + redisTemplate.opsForValue().set(key, JSON.toJSONString(userVO)); + String userJson = redisTemplate.opsForValue().get(key); + log.info(userJson); + } + +} diff --git a/pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties b/pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties new file mode 100644 index 000000000..8a0b9e610 --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +spring.application.name=pangu-examples-cache-single + +# spring-cache \u4E00\u7EA7\u7F13\u5B58 +spring.redis.host=localhost +spring.redis.database=1 +spring.redis.port=6379 +spring.redis.password= + +logging.level.root=INFO +logging.level.com.gitee.pulanos.pangu=INFO \ No newline at end of file diff --git a/pangu-examples/pangu-examples-cache-single/src/main/resources/application.properties b/pangu-examples/pangu-examples-cache-single/src/main/resources/application.properties new file mode 100644 index 000000000..3ed9e2dbd --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/main/resources/application.properties @@ -0,0 +1,17 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +spring.profiles.active=${spring.profiles.active:dev} \ No newline at end of file diff --git a/pangu-examples/pangu-examples-cache-single/src/test/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoServiceTest.java b/pangu-examples/pangu-examples-cache-single/src/test/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoServiceTest.java new file mode 100644 index 000000000..d34153a7a --- /dev/null +++ b/pangu-examples/pangu-examples-cache-single/src/test/java/com/gitee/pulanos/pangu/showcases/cache/single/service/ApiBasedDemoServiceTest.java @@ -0,0 +1,21 @@ +package com.gitee.pulanos.pangu.showcases.cache.single.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApiBasedDemoServiceTest { + + @Autowired + private ApiBasedDemoService apiBasedDemoService; + + @Test + public void testRedisCache() { + apiBasedDemoService.testRedisCache(); + } + +} \ No newline at end of file diff --git a/pangu-examples/pom.xml b/pangu-examples/pom.xml index 13bd8a55b..da252470f 100644 --- a/pangu-examples/pom.xml +++ b/pangu-examples/pom.xml @@ -17,6 +17,7 @@ pangu-examples-config-local pangu-examples-log-dynamic pangu-examples-crud + pangu-examples-cache-single pangu-examples-cache-layering pangu-examples-dubbo-api pangu-examples-dubbo-service -- GitLab