Skip to main content

cache-caffeine-web应用版

提供web应用缓存配置示例,更多使用方式请参考dawdler-cache-caffeine.

1. 单应用版

下载示例dawdler-tutorial.zip,版本为jdk1.8.

解压后,进入cache-caffeine-single-user-web-api目录中.

运行UserWebApplication.java的main方法.

@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}

1.1 项目结构说明

controller -> UserController.java web api的入口

service -> UserService.java 服务接口

service.impl -> UserServiceImpl.java 服务实现层

mapper -> UserMapper.java 数据库操作层

entity -> User.java 实体类

cache.config -> UserCacheConfig 缓存配置类

1.2 使用说明

相关配置参考dawdler-cache-core.

1.3 通过jar包方式运行

通过运行

 mvn clean package

获得 cache-caffeine-single-user-web-api-0.0.1-jdk1.8-SNAPSHOT-all.jar

运行

java -jar cache-caffeine-single-user-web-api-0.0.1-jdk1.8-SNAPSHOT-all.jar

1.4 验证

启动后多次访问 http://localhost:8085/user/info?id=1 其中有一次会调用后台并缓存.第二次之后直接从缓存中获取数据(前提 数据库中有userId=1的用户数据).