title: Java Play 2.5.x JavaCache - How to get the current cache instance?
body: <p>I've followed the example at <a href="https://www.playframework.com/documentation/2.5.x/JavaCache" rel="nofollow noreferrer">https://www.playframework.com/documentation/2.5.x/JavaCache</a> and I can successfully access the cache, but I only seem to be able to do this from a controller method.  Specifically:</p>
  
  <pre><code>@Inject
  public OverviewController(CacheApi cache) { this.lookupCache = cache; }
  </code></pre>
  
  <p>From the controller actions, I can then interrogate the cache as needed via lookupCache.</p>
  
  <p>My problem is that I need this functionality a few layers deeper in the application, and I'd really like to prevent passing a reference to lookupCache through several other constructors.</p>
  
  <p>The documentation seems to suggest the capability of adding this injection on any "component", which would give me what I want, but if I try the same injection on some other class:</p>
  
  <pre><code>public class DropDownCache {
      private CacheApi lookupCache;
      @Inject
      public DropDownCache(CacheApi cache) { this.lookupCache = cache; }
  }
  </code></pre>
  
  <p>...then any time I instantiate DropDownCache, I have to supply the CacheApi instance.  This tells me that the controller is magically being instantiated with this reference, I just don't know how to access it.</p>
  
  <p>Does anyone have any pointers on where the controllers get their instance of CacheApi from?</p>