SpringBoot中快取的應用

2021-09-07 03:03:29 字數 559 閱讀 9139

主要是因為系統中有些介面速度比較慢,其實是sql比較慢(如果想從根本上解決問題的話,其實應該是優化我們的sql),這時候引入快取可以大大提高響應速度

用了快取後,速度確實大大提公升,但是相應帶來的問題是 ==快取的維護==變得複雜,即何時何地需要更新、清除快取?這個是需要針對具體業務具體情況而定的。

pom引入相應jar

org.springframework.boot

spring-boot-starter-cache

啟動類加入註解
@enablecaching
方法上加註解快取

string terminaltypestr = ssouserkit.getterminaltype();

int terminaltype = 1;

if ("mobile".equals(terminaltypestr)) }

清除快取

spring boot 中的快取使用

借鑑 專案中用到登入,對使用者的操作太多,所以將使用者的資訊通過快取的方式。快取 ehcache 框架 spring boot 1.專案依賴 org.springframework.boot spring boot starter cache net.sf.ehcache ehcache 2.ehc...

SpringBoot中的Cache快取 二

1.依賴包 net.sf.ehcache ehcache org.springframework spring context support 4.2.5.release 2.啟動main方法新增快取註解 enablecaching3.實體類實現序列化介面 getter setter noargsc...

Spring Boot中快取的簡單使用

案例 在啟動類上加註解 enablecaching enablecaching public class 在service方法上使用註解 cacheable新增快取 根據id查詢實體 param id return 通過引數id找當前方法的返回值 cacheable value gathering ...