/// <summary> /// Adds a new or update an existing <see cref="TrackingContext"/> in cache with an absolute expiration /// of <paramref name="duration"/>. /// </summary> /// <param name="key"> /// The cache entry identifier, or key, at which to add the new <paramref name="trackingContext"/>. /// </param> /// <param name="trackingContext"> /// The <see cref="TrackingContext"/> to cache. /// </param> /// <param name="duration"> /// The duration, in seconds, after which the <paramref name="trackingContext"/> entry will be removed from the /// cache. /// </param> public virtual void Set(string key, TrackingContext trackingContext, int duration) { if (key.IsNullOrEmpty()) { throw new ArgumentNullException("key"); } if (trackingContext.IsEmpty()) { throw new ArgumentNullException("trackingContext"); } if (duration < 1) { throw new ArgumentException("Expiration duration must be strictly positive.", "duration"); } var cacheItem = new CacheItem(key, trackingContext); var policy = new CacheItemPolicy { AbsoluteExpiration = new DateTimeOffset(DateTime.UtcNow.AddSeconds(duration)) }; _cache.Set(cacheItem, policy); }