title: In-memory cache GetOrCreate with MemoryCacheEntryOptions
body: <p>In current implementation <code>IMemoryCache</code> interface has the following methods: </p>
  
  <pre><code>bool TryGetValue(object key, out object value);
  ICacheEntry CreateEntry(object key);
  void Remove(object key);
  </code></pre>
  
  <p>We have the possibility to query the cache for an entry in the following way: </p>
  
  <pre><code>//first way
  if (string.IsNullOrEmpty
  (cache.Get&lt;string&gt;("timestamp")))
  {
    cache.Set&lt;string&gt;("timestamp", DateTime.Now.ToString());
  }
  
  //second way
  if (!cache.TryGetValue&lt;string&gt;
  ("timestamp", out string timestamp))
  {
      //
      cache.Set&lt;string&gt;("timestamp", DateTime.Now.ToString());
  }
  </code></pre>
  
  <p>But there is another method that should do what a cache should do (<code>GetOrCreate</code>) with a factory parameter: </p>
  
  <pre><code>public static TItem GetOrCreate&lt;TItem&gt;(this IMemoryCache cache, object key, Func&lt;ICacheEntry, TItem&gt; factory)
  {
     object obj;
     if (!cache.TryGetValue(key, out obj))
     {
       ICacheEntry entry = cache.CreateEntry(key);
       obj = (object) factory(entry);
       entry.SetValue(obj);
       entry.Dispose();
     }
     return (TItem) obj;
  }
  </code></pre>
  
  <p>As you can see above, the <code>Set</code> method accepts <code>MemoryCacheEntryOptions</code> or any <code>absoluteExpirationRelativeToNow</code>, <code>absoluteExpiration</code>, etc dates (<a href="https://github.com/aspnet/Caching/blob/12f998d69703fb0f62b5cb1c123b76d63e0d04f0/src/Microsoft.Extensions.Caching.Abstractions/MemoryCacheExtensions.cs" rel="noreferrer">https://github.com/aspnet/Caching/blob/12f998d69703fb0f62b5cb1c123b76d63e0d04f0/src/Microsoft.Extensions.Caching.Abstractions/MemoryCacheExtensions.cs</a>), but <code>GetOrCreate</code> method doesn't support that type of 'per-entry-expiration-date' for when we create a new entry. </p>
  
  <p>I'm trying to figure out if i'm missing something or if i should do a PR to add those methods. </p>
  
  <p>Annex: </p>
  
  <pre><code>public static ICacheEntry SetValue(this ICacheEntry entry, object value)
  {
     entry.Value = value;
     return entry;
   }
  </code></pre>
  
  <p>Opened an issue here: <a href="https://github.com/aspnet/Caching/issues/392" rel="noreferrer">https://github.com/aspnet/Caching/issues/392</a> in order to get some more feedback.</p>