-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend caching for collections #23221
Comments
Thanks for sharing the idea and building a prototype. I don't think such contract is a good fit for a low-level framework abstraction and I've already expressed some concern in #19777 indeed (thought your use case looks different to me). Having said that, we can look at what makes it hard for you to build such aspect in your own code. Can you share the specifics? |
Hi @snicoll, thanks for your feedback. I can totally understand that integrating The first step would be to make changing the provided It would be nice if not only the the Last part is reusing and extending the |
@neiser this looks really promising (I am not a Spring team member, just a developer who found this ticket). While the Spring team is deciding to include it or not would you mind creating a library, that can be accessed from maven central? |
@szantopeter I'm reluctant to create a library without having discussed the integration parts as mentioned above. The final solution would be that some of Spring's caching abstraction are changed such that my code can integrate a bit more seamlessly, and then a library could be created I guess. I hope that the Spring team will find some time soon to work on this. If you desperately need this feature now, feel free to simply copy the code in the PoC project I mentioned above. |
@snicoll Are you going to have a look at this or should this issue be closed? |
@neiser thanks for the nudge and sorry for the late reply. We discussed this one at the team meeting and I forgot to share the outcome of the discussion.
|
@neisen if you happen to create a library out of this, please share the URL. I it would be highly useful for me as a user |
mark to learn |
esp. if you're willing to put some cache in a server-side GraphQL Dataloader Pattern context... See also: |
@mxmlnglt I'd still be happy if I could get some advice from @snicoll how the PoC I shared in the original post can be turned into something worth building a library from, as @szantopeter asked me to do. I don't think the adjustments necessary in the Spring caching layer are actually that large. Just make it a bit more "interceptable" at the right places, and I could build on top of this in a clean way. The current solution is, as outlined, rather crude. |
@mxmlnglt @szantopeter I've created a library here: https://github.com/qaware/collection-cacheable-for-spring It will be available on mvn central soon. |
@neiser Thanks a lot, the library looks great! |
You can use Cache As Multi |
Too bad it's entirely in... Chinese. |
@maxxyme I have added English documents. |
Thanks for your work!! https://github.com/ms100/cache-as-multi/blob/main/README-EN.md |
Cache As Multi looks promising. Can we add similar functionality into the spring cache library? |
I'd like to use the Spring Caching abstraction in a way that I can also ask for a bunch of items via a list of provided IDs, and then put the result into the cache, as if I had asked for each item one by one.
As an example, consider the following snippet:
Then usage would be:
I've implemented this functionality in a proof-of-concept Spring Boot application here: https://github.com/neiser/spring-collection-cacheable The main implementation can be found in
CollectionCacheInterceptor#handleCollectionCacheable
The PoC lacks the following:
BeanFactoryCacheOperationSourceAdvisor
to account for my extraCollectionCacheableCacheAnnotationParser
andCollectionCacheInterceptor
only worked via aBeanFactoryPostProcessor
sync
(might be possible, but is harder to implement)CacheAspectSupport
(which I extended inCollectionCacheInterceptor
) has only some methods protected, which required me to copy some of the code fromCacheAspectSupport
inCollectionCacheInterceptor
Still, the tests in
MyRepositoryIntTest
show that the PoC works 👍My questions to you folks are:
BeanFactoryCacheOperationSourceAdvisor
in order to support my custom@CollectionCacheable
?@CollectionCacheable
could be officially integrated in Spring's caching layer (of course with some more polishing)? I've seen some discussions on Stackoverflow and in particular in Insert all elements of a returned list into a Cache [SPR-15213] #19777 but they lack the "partial" invocation feature as in example 2 above (they proposes to use the Cache/CacheManager interfaces to achieve the desired functionality).@CollectionCacheable
: TheCacheAspectSupport
class is hard to extend for my PoC. The same holds forCollectionCacheableCacheAnnotationParser
, which is extendingSpringCacheAnnotationParser
. Would you mind to make this easier for my use case?I'm happy to contribute a PR once I know what your opinion on this feature is. I can also polish the PoC further following your recommendations. I appreciate any feedback!
The text was updated successfully, but these errors were encountered: