title: Guava LoadingCache not working in SpringBoot app?
body: <p>I have a Guava LoadingCache defined that accepts a search criteria request. The search criteria class properly implements <code>equals</code> and <code>hashCode</code> and this is verified with a unit test. </p>
  
  <p>The cache works properly and caches search results in unit tests but when running as a SpringBoot app, the cache doesnt work and is calling <code>load</code> each time <code>get(key)</code> is called. </p>
  
  <p>I would post my code but I've varified through logging and tests that the cache works other than when running as a SpringBoot fat jar.</p>
  
  <p>Is there something I don't know about Spring that would cause this?</p>
  
  <p>EDIT:
  Class containing LoadingCache:</p>
  
  <pre><code>public class ObjectCache {
  
  private static ObjectCache objectCache = null;
  LoadingCache&lt;Key, Object&gt; serviceCache;
  
  private ObjectCache(){
      System.out.println("creating cache");
      serviceCache = CacheBuilder.newBuilder()
              .expireAfterWrite(20, TimeUnit.MINUTES)   
              .maximumSize(1000)
              .build(new CacheLoader&lt;Key, Object&gt;() {
                  public Object load(Key key) throws Exception {
                      System.out.println("uncached request - calling legacy service: " + key.hashCode());
                      return ServiceCaller.callLegacyFindPatient(key);
                  }
              });
  }
  
  public static ObjectCache getObjectCache(){
      if(_patientCache == null){
          _patientCache = new FindPatientCache();
      }
      return _patientCache;
  }
  
  public LoadingCache&lt;Key, Object&gt; getCache(){
      return this.serviceCache;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The cache is used like so: <code>ObjectCache.getPatientCache().getCache().get(key);</code></p>
  
  <p>In unit tests, the cache works and I see the duplicate hashes. When running as a SpringBoot app, the same calls result in the cache calling the legacy webservice each time even though the hashes show as the same. </p>
  
  <p><strong>EDIT</strong>: Console output when called as SpringBoot app, you can see identical hashes trigger the load.</p>
  
  <pre><code>creating cache
  uncached request - calling native service for key: 2076189345
  uncached request - calling native service for key: 2076189345
  </code></pre>