title: On using Enum based Singleton to cache large objects (Java)
body: <p>Is there any better way to cache up some very large objects, that can only be created once, and therefore need to be cached ? Currently, I have the following:</p>
  
  <pre><code>public enum LargeObjectCache {  
      INSTANCE; 
  
      private Map&lt;String, LargeObject&gt; map = new HashMap&lt;...&gt;();
  
      public LargeObject get(String s) {  
          if (!map.containsKey(s)) {
              map.put(s, new LargeObject(s));
          }
          return map.get(s);
      }
  }  
  </code></pre>
  
  <p>There are several classes that can use the LargeObjects, which is why I decided to use a singleton for the cache, instead of passing LargeObjects to every class that uses it.</p>
  
  <p>Also, the map doesn't contain many keys (one or two, but the key can vary in different runs of the program) so, is there another, more efficient map to use in this case ?</p>