title: Choosing Keys for Guava Cache
body: <p>I am new to Guava cache and looking for some advice.</p>
  
  <p>I would like to cache "functions" - classes responsible for some calculation. Each class has 3 double attributes: start, max, increment</p>
  
  <p>What is the best way to create a key for storing in cache? How about complex object?</p>
  
  <p>I was thinking about using Hasher but for complex objects same hash does not mean same object. So the key-> value will not be unique.</p>
  
  <p>Also, how does Cache look up for key? 
  I noticed that if I use 2 objects for key which pass equals, Cache considers it to be unique keys. Does it work based on key1 == key2? </p>
  
  <pre><code>public static void testGuavaCache() {
      Cache&lt;Object, String&gt; CACHE = CacheBuilder.newBuilder().weakKeys().weakValues().build();
  
      for (int i = 0; i &lt; 2; i++) {
          Joiner joiner = Joiner.on('|');
          String key1 = joiner.join(i, i, i, i, i, i, i);
  
          for (int j = 0; j &lt; 2; j++) {
              String key = joiner.join(i, i, i, i, i, i, i);
              System.out.println(key1.equals(key));
              System.out.println(key1 == key);
              try {
                  String m = CACHE.get(key, new Callable&lt;String&gt;() {
                      @Override
                      public String call() throws Exception {
                          return "test";
                      }
                  });
  
                  System.out.println("Size = " + CACHE.size());
  
              } catch (ExecutionException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>true
  false
  Size = 1
  true
  false
  Size = 2
  true
  false
  Size = 3
  true
  false
  Size = 4
  </code></pre>
  
  <p>Removing weakKeys() solves the problem. Is this expected?</p>