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

Add support for different collection types #8

Closed prokop7 closed 3 years ago

prokop7 commented 3 years ago

Issue

@CachableCollection supports only Collection<?> arguments, it's not ideal for real use, often programmers use Set<?> or List<?>

Proposed solution

Replace check arg[0].class.equals(Collection.class) with Collection.class.isAssignableFrom(arg[0].class).

We have to decide what type of collection we have to create. The condition is that arg[0].class has to be assignable from this collection. To deal with it CollectionCreator interface is provided. Currently it consists two implementations: DefaultCollectionCreator which creates LinkedList, SetCollectionCreator that works with HashSet

neiser commented 3 years ago

@prokop7 Thanks for this PR. I'm willing to merge it as it looks reasonable. Can you look at my little review remarks?

prokop7 commented 3 years ago

Also, I've fixed the misconfiguration of Cache Interceptor, it requires factoryBean to be able to get Caches