Expiration Troubleshooting (Windows Server AppFabric Caching)

Windows Server AppFabric uses expiration to control the lifetime of objects in the cache. Expiration itself is a ordinary part of the architecture of AppFabric caching, but you may have to troubleshoot issues related to expiration settings. For more information about expiration, see Expiration and Eviction.

Diagnosing Expiration Problems

As objects are added to the cache, the memory used by the cache approaches the memory low watermark. You can see the CacheSize and the LowWatermark settings with the Get-CacheHostConfig Windows PowerShell command. You can see the current amount of memory used on a cache host by observing the AppFabric Caching:Host | Total Data Size Bytes counter in Performance Monitor. After the memory low watermark is reached, the cache cluster periodically removes expired items from the cache. When the memory high watermark is reached, the cache cluster also removes expired objects from the cache in addition to evicting least recently used items.

It is difficult to identify specific problems with expiration settings by observing only the behavior of the cache with tools such as Performance Monitor. Instead, it is better to view the default expiration settings for each cache to determine whether the expiration settings are appropriate for the type of data in the cache. There are two main considerations:

  • Is the expiration time too short? In this case applications may experience more cache misses that require re-adding items to the cache.

  • Is the expiration time too long? If the cache cluster has a high volume of insertions or very long expiration times, it is possible that the memory high watermark is reached before cached items have expired. This causes an eviction run. For more information about eviction, see Eviction Troubleshooting (Windows Server AppFabric Caching).

The following Windows PowerShell script displays each cache, its expiration setting, and the default expiration time in minutes.

$caches = Get-Cache -MaxRegions 0
foreach($cache in $caches) { Write-Host $cache.CacheName (Get-CacheConfig $cache.CacheName).IsExpirable (Get-CacheConfig $cache.CacheName).TimeToLive }

Consider the following sample output from the previous script.

Cache1 True 10
Cache2 True 10
Cache3 True 1
Cache4 False 10
default True 10

In the previous example output, you can see that most of the caches use the default settings: expiration is enabled and the expiration time is ten minutes. Cache3 has expiration enabled, but the expiration time is one minute. You should examine the clients of Cache3 to see whether one minute is enough time for those clients to get the benefit of caching the items. Cach4 has expiration disabled, so the value of ten minutes does not apply. You should examine the clients of Cache4 to see whether there is a valid reason to disable expiration on this cache. You should also examine the size of Cache4 to see whether it contains large amounts of data that could contribute reaching the memory high watermark on the cache host.

Important

Even though these cache settings show the default values, applications can control expiration on individual items that they add. If an application specifies a time-out value for an item, that time-out value overrides the cache setting. Also, if the application locks an item in the cache, that item remains in the cache even if it has expired.

Resolving Expiration Problems

Once you have determined that the expiration settings should change, you can use the Set-CacheConfig Windows PowerShell command to change the expiration settings. The following command changes the expiration settings for Cache1 to enable expiration with an expiration time of five minutes.

Set-CacheConfig Cache1 -Expirable true -TimeToLive 5

If the expiration settings are being controlled by an application, then a developer must change the application to adjust the expiration time or locking state of the cached items.

See Also

Concepts

Troubleshooting Server Issues (Windows Server AppFabric Caching)