0

Is it possible to have cached queries asynchronous, so that no frontend user actually has to wait for a heavy query to finish? (I.e. heavy query is running as background thread, while (expired) data is delivered from cache.

Use case: A web page displaying data, needing some time (too long to wait for when requesting a page) to be collected from the database. Simply caching the data for one hour means that every hour one user has to wait for the query to finish.

I would like to have something like this: The first user to request (expired) data from cache, will be delivered expired data. In the background, a separate thread is started which will update the cached data from the database. The next user will see fresh data.

Is there a standard solution for this, without having to do the caching oneself? Ideally, using ehcache & springmodules.

Thanks :)

PeterP
  • 4,502
  • 7
  • 22
  • 21
  • It's easy to implement this using Spring's scheduling and caching abstractions. See @Matteo 's answer: https://stackoverflow.com/a/31048024/746718 – oskansavli Jun 05 '18 at 13:49

1 Answers1

0

Obviously, there is no out of the box solution.

We are going to implement our own interceptor.

PeterP
  • 4,502
  • 7
  • 22
  • 21
  • Any newer updates on this @PeterP. I am in need of a similar solution for a similar solution. Did you find any other newer alternatives to resolve this problem rather than writing your own interceptor? – Einstein_AB Mar 27 '20 at 10:09