Im using the Cache-Abstraction of Spring with the CaffeineCache implementation.
In my JpaRepository are two methods:
Article findByArticleId(final Long articleId);
List<Article> findByArticleIdIn(Set<Long> articleIds);
To make them Cachable i would use:
@Cacheable(value = "article_cache", key = "#articleId")
Article findByArticleId(final Long articleId);
@Cacheable(value = "article_cache", key = "#articleIds")
List<Article> findByArticleIdIn(Set<Long> articleIds);
Now my question: Is Spring "smart enough" to store only Article-Objects as cached values or would this result in two different types of keys and values?
If both methods are invoked for partially the same ids. Would the cache look like this (not good):
{
"[1,2,3,4,5]": [Article@1, Article@2,..],
"[2,3,4]": [Article@2, Article@3,..],
"1": Article@1,
"2": Article@2,
...
}
Or like this (wanted behavior):
{
"1": Article@1,
"2": Article@2,
"3": Article@3,
"4": Article@4,
...
}
The Article objects are quite large. If the first behavior is true, how could I achieve the second one without implementing a custom cache?
Thanks in advance!