Поделиться через


Design of the Scavenging Process

The Caching Application Block's scavenging process is performed by the BackgroundScheduler object. It checks the cache every time an item is added to see if the number of items in the cache has reached a predetermined limit. You use the configuration tools to set this limit when you configure an instance of a cache manager. You also set how many items are removed from the cache after scavenging begins.

When an item is added to the cache, the code can set one of four priority settings: Low, Normal, High, or NotRemovable. The BackgroundScheduler object determines which items should be scavenged by doing a major sort based on priority and a minor sort based on the last time the item was accessed. For example, an item with a Low priority that has just been used will be scavenged before something with a High priority that has not been accessed for three years. The default value is Normal.

The NotRemovable priority is used when you want an item to remain in the cache until it expires. However, the cache should not be used as the only location where an item of data exists. A cache should be used to improve performance; it should not be used as a form of permanent storage.

Unlike the expiration process, the scavenging process performs marking and sweeping in a single pass. For more information about marking and sweeping, see Design of the Expiration Process.