Timeouts

AppFabric’s DataCache class allows you to set the amount of time that the object will reside in the cache before expiration using either the Add or Put methods.

ScaleOut StateServer allows you to set timeouts (and many other cache policies) on an object-by-object basis using the CreatePolicy class when inserting an object into the cache.

NamedCache cache = CacheFactory.GetCache("Sample Cache");

// Insert an object with a 20 minute timeout:
CreatePolicy policy = new CreatePolicy();
policy.Timeout = TimeSpan.FromMinutes(20);
policy.IsAbsoluteTimeout = true;
cache.Insert("Key2", "Object value with 20 min timeout",
             policy, true, false);

The IsAbsoluteTimeout property specifies whether the timeout is absolute (that is, the object expires after the elapsed time regardless of whether it’s accessed) or sliding (the timeout resets back to its original timeout every time it is accessed).