title: Spring Boot Native cache : How to expire/remove cache data by individual keys/elements
body: <p>We are calling Identity federation service to acquire user tokens very frequently and almost running load test on Identity service.</p>
  
  <p>A potential solution is to cache the user tokens in existing application, however with native spring-cache, can we expire individual cache entries ?</p>
  
  <p>With below example, I was able to clear the cache, removing all entries, however I am trying to expire individual entries.</p>
  
  <pre><code>@Service
  @CacheConfig(cacheNames =  {"userTokens"})
  public class UserTokenManager {
  
      static HashMap&lt;String, String&gt; userTokens = new HashMap&lt;&gt;();
  
      @Cacheable
      public String getUserToken(String userName){
          String userToken = userTokens.get(userName);
          if(userToken == null){
              // call Identity service to acquire tokens
              System.out.println("Adding UserName:" + userName + " Token:" + userToken);
              userTokens.put(userName, userToken);
          }
          return userToken;
      }
  
      @CacheEvict(allEntries = true, cacheNames = { "userTokens"})
      @Scheduled(fixedDelay = 3600000)
      public void removeUserTokens() {
          System.out.println("##############CACHE CLEANING##############, " +
              "Next Cleanup scheduled at : " + new Date(System.currentTimeMillis()+ 3600000));
          userTokens.clear();
      }
  }
  </code></pre>
  
  <p>Spring-boot application class is as below:</p>
  
  <pre><code>@SpringBootApplication
  @EnableCaching
  @EnableScheduling
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>