Reputation: 35
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>
Upvotes: 1
Views: 1461
Reputation: 2860
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
.
Upvotes: 1