Skip to content
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

Feature Request: Quarkus Caching Hooks #32413

Open
The-Funk opened this issue Apr 4, 2023 · 3 comments
Open

Feature Request: Quarkus Caching Hooks #32413

The-Funk opened this issue Apr 4, 2023 · 3 comments
Labels
area/cache kind/enhancement New feature or request

Comments

@The-Funk
Copy link

The-Funk commented Apr 4, 2023

Description

I'd like to watch for the expiration of data within a Quarkus Cache. When an entry expires and is ejected from cache, I'd like the key and value being ejected to be passed to a custom hook so that I may perform some action.

Use case: I have an upstream database that provides data to my service. Its caching options are much more simplistic than my Quarkus application's caching options. Via my Quarkus service I can tell that upstream service to cache data for me and I can set an expiration time and that's it. Basically an expire after write. I can also tell this external database to drop cached results. Unfortunately there's no way for me to trigger this external service to drop results without a scheduled method. It would be cool if I could cache a reference to the stored results and when my reference cache expires after access, I could trigger the remote service to drop its cache as well.

Implementation ideas

I'm not great at writing hooks and callbacks but here's a quick idea of how this could look based on what I know about Quarkus.

@CacheExpirationHook(cacheName="my-cache")
void onMyCacheValueEjection(String key, SomeType value) {
    // key and value are passed from the cache's triggered expiration event
    // tell remote service to drop cache
    // do some other things here
}
@CacheHook(cacheName="my-cache")
void onMyCacheValueEjection(@Observes cacheEjectionEvent ejected) {
    ejected.getKey();    // The key ejected from cache
    ejected.getValue(); // The value ejected from cache
    // tell remote service to drop cache
    // do some other things here
}
@The-Funk The-Funk added the kind/enhancement New feature or request label Apr 4, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 4, 2023

/cc @gwenneg (cache)

@The-Funk The-Funk changed the title onCacheExpiration Hooks Feature Request: Quarkus Caching Hooks Apr 4, 2023
@geoand
Copy link
Contributor

geoand commented Apr 5, 2023

This sounds interesting, but I am pretty sure it would only be possible in the Caffeine backed cache implementation

@The-Funk
Copy link
Author

The-Funk commented Apr 5, 2023

@geoand I was kind of afraid of that. Looking at Caffeine I knew it was possible there but I know you have several providers you support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants