qaware / collection-cacheable-for-spring

Spring cache extension for putting a whole collection of entities as single cache items
Apache License 2.0
58 stars 9 forks source link

CollectionCacheable returning a list of entities #17

Closed jaimearroyo7 closed 2 years ago

jaimearroyo7 commented 2 years ago

Hey @neiser ! First of all thank you for this project, it's really nice.

My question here is if there is any way to make it work in functions like this?

@CollectionCacheable(cacheNames = "myCache")
public List<MyEntity> findByIds(Collection<Long> ids)

If not, is there any way I could contribute to make this possible? It would be really useful to be able to do so.

prokop7 commented 2 years ago

I think it is possible to do so. I would write a result converter that would convert Map<K, V> to whatever you want. Just make it extendable enough to be able to write custom converters

neiser commented 2 years ago

@jaimearroyo7 I'll look into this asap, also @prokop7 is right that it should be doable. I'll also improve the existing CollectionCreator usage as well.

neiser commented 2 years ago

@jaimearroyo7 I've pushed to master a first solution supporting List<MyEntity> return types. However, the class MyEntity must implement the support interface HasCacheKey, which returns an object of the same type as the passed in ids items (in your case, it's probably the entity id of type Long).

Please try out the snapshot version for your use case. If you find it useful as it is, I'll release it as 1.3.0, if not, please report what could be improved.

jaimearroyo7 commented 2 years ago

@neiser Thank you very much for your reply! I will take a look, play with it and tell you something ASAP!!

jaimearroyo7 commented 2 years ago

Hey! I'm getting a java.lang.IllegalStateException: Cannot find appropriate return value converter for method public java.util.List ........ Available are: [de.qaware.tools.collectioncacheableforspring.returnvalue.DefaultReturnValueConverter@2ff452dd] am I missing something?

MyEntity already implements HasCacheKey with public Object getCacheKey() {return id;}

neiser commented 2 years ago

@jaimearroyo7 I forgot to add the bean in the auto configuration. I've just pushed a fixed and the newest -SNAPSHOT release should hopefully work for you.

jaimearroyo7 commented 2 years ago

It's working now, thank you very much!! 🎉 🎉 🎉

I think it can be released as 1.3.0! 🚀

jaimearroyo7 commented 2 years ago

Hey @neiser !! Have you been able to publish it already? I'd like to use it as maven dependecy 😅 😅 😅 . But no hurry of course, it's your project!!

neiser commented 2 years ago

@jaimearroyo7 I've just released it as 1.3.0. Sorry for being slow with this, but I was a little bit concerned about the performance implications of my change. But anyhow, that can be improved in future releases. There's no reason to hold this feature back.