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

Specify parameter cache key #39

Closed galid1 closed 1 year ago

galid1 commented 1 year ago

Hi there, I wonder why, there is no way that I make method that, has two or more parameter.

I think that it can be easily done by making field annotation.

So can u develop it? If not, I want to know that reason.

neiser commented 1 year ago

Hi @galid1 @CollectionCacheable supports the key parameter as the [@Cacheable annotation does](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html#key()), as this library simply delegates obtaining the cache key to the Spring framework, see here.

I'm closing this issue, as I don't fully see what else you'd need to be delevoped. Please come up with a "minimally working example" (or broken example) demonstrating your use case (feel free to comment this issue still, I'll re-open if necessary). Then I can see how I can help you.

galid1 commented 1 year ago
    @CollectionCacheable(cacheNames = [CACHE_KEY_GET_BUSINESS_USER_BY_ID], putNull = false, key = "#ids")
    fun listByIds(ids: List<Long>, option: BusinessUserFilterOption?): List<CacheWrapper<BusinessUserDto>> {
        return businessUserRepository.findAllById(ids)
            .filterByOption(option)
            .map {
                CacheWrapper(
                    cacheKey = it.id!!,
                    cacheTarget = BusinessUserDto.fromEntity(it)
                )
            }
    }

Here is the case. Then, it throws an error with following msg "Did not find exactly one Collection-like argument".

I already know, it can be done done by using repository cache. But, I think it is not good. Because it makes entity have to know third party lib.