org.springframework.boot spring-boot-starter-cache net.sf.ehcache ehcache
創(chuàng)建ehcache.xml配置文件
修改springboot配置文件,引入ehcache.xml配置文件spring:
cache:
type: ehcache
ehcache:
config: classpath:ehcache/ehcache.xml
啟用@EnableCaching
注解@SpringBootApplication
@EnableCaching
public class Application{public static void main(String[] args) {SpringApplication.run(Application.class, args);
}
}
實(shí)體類(lèi)實(shí)現(xiàn)可序列化接口Serializable由于需要實(shí)體類(lèi)支持緩存中的磁盤(pán)存儲(chǔ),所以需要實(shí)體類(lèi)實(shí)現(xiàn)可序列化接口。
public class User implements Serializable{...
}
添加緩存注解@Cacheable
、@CacheEvict
@Cacheable
緩存數(shù)據(jù)@Service
public class UserServiceImpl implements UserService {@Autowired
private UserMapper userMapper;
@Override
@Cacheable(value="users")
public User selectUserById(int id) {User user=this.userMapper.selectUserById(id);
System.out.println("load data from db");
return user;
}
}
@CacheEvict
清除緩存@Service
public class UserServiceImpl implements UserService {@Autowired
private UserMapper userMapper;
@Override
@Cacheable(value="users")
public User selectUserById(int id) {User user=this.userMapper.selectUserById(id);
System.out.println("load data from db");
return user;
}
@CacheEvict(value="users", allEntries=true)
public void saveUsers(Users users) {this.userMapper.save(users);
}
@CacheEvict(value="users", allEntries=true)
public void deleteUserById(int id) {this.userMapper.deleteUserById(id);
}
}
其它
設(shè)置java.io.tmpdir
子目錄
參考https://www.cnblogs.com/xzmiyx/p/9897623.html
https://blog.csdn.net/qq_33285292/article/details/108152912
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧