spring中Cache用什麼map實現快取

2021-10-04 11:42:37 字數 1531 閱讀 9453

配置快取註解版

啟動類上新增@enablecaching、

具體方法上@cacheable(value = 「menucache」),key是底層建立的

為了防止查詢資料出現髒讀,在關於查詢資料的刪除資料方法上新增@cacheevict(value = 「menucache」,allentries = true)

從cachemanager介面中查詢

public

inte***ce

cachemanager

然後找到實現類

private final concurrentmapcachemap = new concurrenthashmap(16);中的string就是之前的使用者自定義註解value

public

class

concurrentmapcachemanager

implements

cachemanager

, beanclassloaderaware }}

return cache;

}

建立的cache內容儲存物件

new concurrentmapcache

protected cache createconcurrentmapcache

(string name)

concurrentmapcache這個map通過聚合關係獲得

建立了new concurrenthashmap(256)高併發的map

public

class

concurrentmapcache

extends

abstractvalueadaptingcache

最終放入concurrenthashmap中,訪問都是在這個map中

獲取

@nullable

protected object lookup

(object key)

儲存

public

void

put(object key,

@nullable object value)

這個類用到concurrentmap

public

class

concurrentmapcache

extends

abstractvalueadaptingcache

{private

final string name;

private

final concurrentmap

store;

spring 3 1中的cache小結

spring 3.1中有cache了,下面結合目前網上的一些資料和手冊的歸納總結下 1 cache註解 在3.1中,都是用註解的了,cacheable註解可以用在方法或者類級別。當他應用於方法級別的時候,就是如上所說的快取返回值了。當應用在類級別的時候,這個類的所有方法的返回值都將被快取。cache...

spring快取cache的使用

在spring配置檔案中新增schema和spring對快取註解的支援 xmlns xmlns aop xmlns xsi xmlns mvc xmlns context xmlns tx xmlns p xmlns cache xsi schemalocation spring beans 3.0...

spring的Cache註解和redis的區別

1 不支援ttl,即不能設定過期時間 expires time,springcache 認為這是各個cache實現自己去完成的事情,有方案但是只能設定統一的過期時間,明顯不夠靈活。2 內部呼叫,非 public 方法上使用註解,會導致快取無效。內部呼叫方法的時候不會呼叫cache方法。由於 spri...