SpringBoot与Cacheable
SpringBoot与Cacheable
Demo
项目结构
项目源码
package com.supremepole.b04springbootcachesingle;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class B04SpringBootCacheSingleApplication {
public static void main(String[] args) {
SpringApplication.run(B04SpringBootCacheSingleApplication.class, args);
}
}
package com.supremepole.b04springbootcachesingle;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
/**
* @author CodeCoderCoding
*/
@Repository
public class WebsiteDao {
@Cacheable("c1")
public Website getWebsiteId(Integer id){
Website website=new Website();
website.setId(id);
website.setName("supremepole");
website.setUrl("https://cs.supremepole.com");
return website;
}
}
package com.supremepole.b04springbootcachesingle;
import java.io.Serializable;
/**
* @author CodeCoderCoding
*/
public class Website implements Serializable {
private int id;
private String url;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString(){
return "id="+id+" ,name"+name+" ,url"+url;
}
}
server.port=8081
spring.cache.cache-names=c1,c2
spring.cache.redis.time-to-live=1800s
spring.redis.database=0
spring.redis.host=
spring.redis.port=
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.max-wait=-1ms
spring.redis.jedis.pool.min-idle=0