How can I configure Spring cache to accept an int variable as a key?
I tried the following but has not worked. I did read in the API, and I saw that the value for the key must be string. So I'm not 100% sure what is the properly configuration
I tried use this annotation in my method:
@Cacheable(cacheNames="GETREQUIREMENTPRIVATE", key = "#RequirementID")
private Requirement getRequirement(final int RequirementID, final Connection connection)
And I did set this in my ehcache.xml file:
<cache name="GETREQUIREMENTPRIVATE"
statistics="true"
maxElementsInMemory="1000"
eternal="true"
memoryStoreEvictionPolicy="LFU">
</cache>
You can use Integer
for the key, but not primitive int
there should is Object because for getting String key will use.toString() method. So Integer
, not int
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.