title: Memory Cache in web api
body: <p>I was looking for <a href="https://stackoverflow.com/questions/26398129/caching-search-result-in-web-api">Caching</a> in my web api where i can use output of one api method(that changes once in 12hrs) for subsequesnt calls and then i found <a href="https://stackoverflow.com/questions/16443795/caching-data-in-web-api?rq=1">this solution</a> on SO,but i am having a difficulty in understanding and using the below code</p>
  
  <pre><code>private IEnumerable&lt;TEntity&gt; GetFromCache&lt;TEntity&gt;(string key, Func&lt;IEnumerable&lt;TEntity&gt;&gt; valueFactory) where TEntity : class 
  {
      ObjectCache cache = MemoryCache.Default;
      var newValue = new Lazy&lt;IEnumerable&lt;TEntity&gt;&gt;(valueFactory);            
      CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(30) };
      //The line below returns existing item or adds the new value if it doesn't exist
      var value = cache.AddOrGetExisting(key, newValue, policy) as Lazy&lt;IEnumerable&lt;TEntity&gt;&gt;;
      return (value ?? newValue).Value; // Lazy&lt;T&gt; handles the locking itself
  }
  </code></pre>
  
  <p><strong>I am not sure how to call and use this method in below context?</strong>
  I have a method Get</p>
  
  <pre><code>  public IEnumerable&lt;Employee&gt; Get()
      {
          return repository.GetEmployees().OrderBy(c =&gt; c.EmpId);
      }
  </code></pre>
  
  <p>and i want to cache the output of Get and use it in my other methods GetEmployeeById() or Search()</p>
  
  <pre><code>        public Movie GetEmployeeById(int EmpId)
          {
             //Search Employee in Cached Get
          }
  
          public IEnumerable&lt;Employee&gt; GetEmployeeBySearchString(string searchstr)
          {
            //Search in Cached Get
          }
  </code></pre>