title: Caching using Supplier Java 8
body: <p>This method, as I know, memorizes (caches) the value of supplier that passed as the parameter. As I understand It behaves like singleton pattern. Can anyone explain how it works? </p>
  
  <pre><code>  public static &lt;T&gt; Supplier&lt;T&gt; memoize(final Supplier&lt;? extends T&gt; valueSupplier)
    {
      final List&lt;T&gt; memoryList= new ArrayList&lt;&gt;();
      return () -&gt; {
        if (memoryList.isEmpty()) {
          memoryList.add(valueSupplier.get());
        }
        return memoryList.get(0);
      };
    }
  </code></pre>
  
  <p>Usage like this:</p>
  
  <pre><code>Supplier&lt;SomeClass&gt; cachedValue = memoize(() -&gt; someClassObject.getSomeValueToBeCached());
  cachedValue.get().doMethod();
  </code></pre>