1、在springboot的啟動類上新增註解@enablecaching
,開啟springcache快取支援
// 開啟springcache快取支援
@enablecaching
public
class
}2、在service的方法上新增對應的註解
/**
* 根據id查詢
* * @param id
* @return
*/// 使用springcache進行快取資料庫查詢
@cacheable
(value =
"gathering"
, key =
"#id"
)public gathering findbyid
(string id)
/**
* 修改
* * @param gathering
*/// 修改資料庫資料後需要刪除redis中的快取
@cacheevict
(value =
"gathering"
, key =
"#gathering.id"
)public
void
update
(gathering gathering)
/** * 刪除
* * @param id
*/// 刪除資料庫資料後需要刪除redis中的快取
@cacheevict
(value =
"gathering"
, key =
"#id"
)public
void
deletebyid
(string id)
使用SpringCache進行快取資料庫查詢方式
目錄 開啟springcache快取支援 springbootapplication 開啟springcache快取支援 enablecaching public class gatheringapplication 根據id查詢 param id return 使用springcache進行快取資...
spring cache簡單使用
spring從3.1起自帶了cache功能。可以快取乙個方法的返回值,也就是說如果有快取,spring就會直接使用快取值,而不會再去執行這個方法 cashe相關的功能是在spring context.4.2.5.release.jar這個jar包中的。然後,開啟cache註解,配置cachemana...
Spring Cache抽象 使用SpEL表示式
在spring cache註解屬性中 比如key,condition和unless spring的快取抽象使用了spel表示式,從而提供了屬性值的動態生成及足夠的靈活性。下面的 根據使用者的usercode進行快取,對於key屬性,使用了表示式自定義鍵的生成。public class userser...