![](/img/trans.png)
[英]Ehcache automatic key generation and @Cacheable spring annotation
[英]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.