Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:28:19+00:00 2026-06-06T18:28:19+00:00

Can the Spring @Cacheable be configure so that if there is a cache miss

  • 0

Can the Spring @Cacheable be configure so that if there is a cache miss calls to the cacheable method get blocked until the cacheable method executes once and the cache is populated?

In my case I am dealing with data from the db that does not change often in fact if this data changes then the app will need to be restarted. I can create @PostConstruct methods and init the data as each service is launching but that does not seem as “elegant” as the @Cacheable annotation.

I am planning to use EhCache with the Spring @Cacheable annotation.

update:

Here are some issues that I ran into in trying to use @PostConstruct, in case some one else run into those issues. @PostConstruct methods can’t be @Transactional because they run after the properties of the object are set and not after the whole spring context is configured. So you can’t assume that the TX manager is all setup and configured by the time @PostConstruct method is called. The workaround for this is to implement a ApplicationListener and inject a TransactionTemplate manually … etc a lot of extra work that is simplified by using @Cacheable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:28:20+00:00Added an answer on June 6, 2026 at 6:28 pm

    I don’t think @PostConstruct is inelegant, seems perfect solution to me. You want the method(s) called only when app is restarted. What could be better ?

    But you can also do this to block calls until a cache is available

    @Cacheable(cacheName="yourCache", decoratedCacheType= DecoratedCacheType.SELF_POPULATING_CACHE)
    public List<String> getWhatever(int id) {
    //call database
    }
    

    and to make the cache autorefresh this :

    @Cacheable(cacheName="yourCache", refreshInterval=1000, decoratedCacheType= DecoratedCacheType.REFRESHING_SELF_POPULATING_CACHE)
    public List<String> getWhatever(int id) {
      //call database
    }
    

    kudos

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I make the spring service classes final? Is there any harm doing that?
I understand that spring can manage your sessions for you, if configured like so:
Is it possible to assure that only spring can instantiate a class, and not
I want to use both ContextLoaderListener (so that I can pass Spring Beans to
This is just a curiosity question. I know that Spring can be used in
With Spring MVC, you can specify that a particular URL will handled by a
Using Spring : can jta-transaction-manager use id as name so that I can pass
I've noticed recently that spring can wire up my ejb's for me if I
Is it correct that one can create spring beans using just the @Component annotation
Given a set of classes wired together by spring. There are several classes that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.