簡體   English   中英

Spring 緩存配置到變量 int 作為 @Cacheable 注釋中的鍵

[英]Spring Cache configuration to variable int as key in @Cacheable annotation

如何配置 Spring 緩存以接受 int 變量作為鍵?

我嘗試了以下但沒有奏效。 我確實閱讀了 API,我看到鍵的值必須是字符串。 所以我不是 100% 確定什么是正確的配置

我嘗試在我的方法中使用這個注釋:

@Cacheable(cacheNames="GETREQUIREMENTPRIVATE", key = "#RequirementID")
private Requirement getRequirement(final int RequirementID, final Connection connection)

我確實在我的 ehcache.xml 文件中設置了這個:

<cache name="GETREQUIREMENTPRIVATE"
statistics="true"
         maxElementsInMemory="1000"
         eternal="true"
         memoryStoreEvictionPolicy="LFU">
</cache>

您可以使用Integer作為密鑰,但不是原始int應該是 Object 因為獲取字符串密鑰將使用 .toString() 方法。 所以Integer ,不是int

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM