APGen Documentation Previous Topic: Item Expiration Next Topic: Shrinking Parent Topic: Introduction to ASPCache    Introduction to ASPCache
Flushing
See Also:

ASPCache flushing is used to remove items in the cache that have not been used in a while.  Caching is only valuable when the cached items are re-used.  ASPCache's flushing capabilities support automatic removal of items that are not re-used often.  Flushing frees memory and other valuable resources, while retaining the cached items that are frequently used and thus more valuable.

The properties that control flushing apply to the cache object - they affect all items held in the cache.  Whereas expiration is a per-item setting, flush settings are cache-wide.

Like expiration and shrinking, flushing occurs on a lower priority background thread.  The overhead of scavenging for rarely-used items will never slow an ASP page.

The FlushEnabled property enables and disables flushing.  By default, flushing is disabled.  To enable flushing:

' Enable flushing
Cache.FlushEnabled = True

The FlushTimeout property specifies the threshold for determing if an item should be flushed: If an item has not been accessed for a period of time >= FlushTimeout, it is removed.  Like all ASPCache time properties, FlushTimeout is specified in milliseconds.

' Flush items that haven't been used in 2 minutes
Cache.FlushTimeout = 120000

The FlushInterval property specifies how often the background thread should scavenge for items to be flushed.  As long as the CPU is not busy with higher priority tasks, the background thread will perform the scavenge every FlushInterval milliseconds.

' Flush items every minute
Cache.FlushInterval = 60000

The Flush() method starts the background scavenging thread immediately.  To start a flush operation:

' Start a flush now
Cache.Flush

If you want to make some items flushable, but keep other items in the cache permanently, the solution for ASPCache 1.x is to instantiate 2 different ASPCache objects in global.asa:

' *** global.asa ***

' TempCache holds items that may be flushed
' PermCache hold items that will never be flushed
<OBJECT RUNAT=Server SCOPE=Application ID=TempCache PROGID=ASPCache></OBJECT>
<OBJECT RUNAT=Server SCOPE=Application ID=PermCache PROGID= ASPCache></OBJECT>

<SCRIPT LANGUAGE=VBScript RUNAT= Server>

Option Explicit

Sub Application_OnStart
     ' Initialize the TempCache object
     TempCache.FlushEnabled = True
     TempCache.FlushTimeout = 120000
     TempCache.FlushInterval = 60000
End Sub
</SCRIPT>