title: Caching properties using spring Cache
body: <p>I am trying to implement caching to my method using spring cache. The issue is that after first time this method is not getting executed, which means property is not getting loaded. If I remove @Cacheable annotation, it works fine. My requirement is whenever new property is added only then this method should run and load properties else it should return from cache.</p>
  
  <pre><code> @Cacheable("mycache")
  public Properties loadPropertyFile() throws Throwable {
      Properties properties = new Properties();
      try {
          logger.debug("Loading properties.");
          if (this.locations != null) {
  
              for (Resource location : this.locations) {
                  if (logger.isInfoEnabled()) {
                      logger.info("Loading properties file from " + location);
                  }
                  try {
                      properties = PropertiesLoaderUtils.loadAllProperties(location.getFilename());
  
                  } catch (IOException ex) {
                      if (this.ignoreResourceNotFound) {
                          if (logger.isWarnEnabled()) {
                              logger.warn("Could not load properties from "
                                      + location + ": " + ex.getMessage());
                          }
                      } else {
                          throw ex;
                      }
                  }
              }
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      return properties;
  }
  </code></pre>
  
  <p>XML File:</p>
  
  <pre><code> &lt;cache:annotation-driven /&gt;
  
  
  &lt;bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"&gt;
  &lt;property name="caches"&gt;
    &lt;set&gt;
      &lt;bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="mycache" /&gt;
    &lt;/set&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p></p>