title: Expiring a cached item via CacheItemPolicy in .NET MemoryCache
body: <p>I'm confused about the AbsoluteExpiration property on CacheItemPolicy.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.cacheitempolicy.absoluteexpiration.aspx" rel="noreferrer">The MSDN documentation for it</a> says "The period of time that must pass before a cache entry is evicted."  It uses a System.DateTimeOffset to define the "period of time".  </p>
  
  <p>But if you look at <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx" rel="noreferrer">DateTimeOffset's MSDN documentation</a>, it says that it "represents a point in time ... relative to Coordinated Universal Time (UTC)."  Reference also this <a href="https://stackoverflow.com/questions/9073149/difference-between-datetime-and-datetimeoffset?lq=1">StackOverflow thread</a>.</p>
  
  <p>Do you see the problem?  AbsoluteExpiration expects a "period in time" (like 5 seconds or 2 hours), but it requires an object that represents a "point in time" (like Dec 21, 2012, 06:14:00 EST).</p>
  
  <p>In the code below, I define a single policy for all items.  I want every item to expire <code>cacheExpiryInSeconds</code> seconds after they are added.  Can someone verify that I'm doing this the correct way?</p>
  
  <pre><code>public class MyCache : IRoutingInfoCache
  {
      MemoryCache _routingInfoCache;
      CacheItemPolicy _cachePolicy;
  
  
      public MyCache(int cacheExpiryInSeconds)
      {
          _routingInfoCache = new MemoryCache("myCache");
          _cachePolicy = new CacheItemPolicy() {
              AbsoluteExpiration = 
                  new DateTimeOffset(
                      DateTime.UtcNow.AddSeconds(cacheExpiryInSeconds))
          };
      }
  
  
      public void Put(string key, object cacheItem)
      {
          // based on how I constructed _cachePolicy, will this item expire
          // in cacheExpiryInSeconds seconds?
          _routingInfoCache.Add(new CacheItem(key, cacheItem), _cachePolicy);
      }
  }
  </code></pre>