APGen Documentation Previous Topic: Collection Functionality Next Topic: Item Expiration Parent Topic: Introduction to ASPCache    Introduction to ASPCache
Item Handles
See Also:

Either string keys or handles can be used to access items in an ASPCache object.  Handles allow O(1) access, which is the fastest possible.  Though the ASPCache string key lookup algorithm is very fast, it is best to use handles when repeatedly accessing the same item in the Cache.

This code snippet uses a string key for the first lookup, then uses a handle for later reference to the same item:

' Retrieve a handle, then get info about the item
Dim h, sKey, vValue, nHits, tInCache, tSinceLastUse

h = Cache.HandleOf("key1")      ' Get the handle for a particular item - O(log n) lookup
vValue = Cache(h)               ' The Value for this item              - O(1) lookup
nHits = Cache.Hits(h)           ' The # of hits on this item           - O(1) lookup
tInCache = Cache.TimeInCache(h) ' How long this object has been in the cache - O(1) lookup
tSinceLastUse = Cache.TimeSinceLastUse(h) ' How long since last use    - O(1) lookup

Handles are similar to, but different than, numeric indexes.  For an object like ASPCache that can be modified by different web pages at the same time, ordered numeric indexes are inappropriate because they can change as other pages delete and insert neighboring items.  The handle for a given item never changes, unless the item is deleted by another page.

When new items are added to an ASPCache object, a string key must be specified.  For all other access, either a string key or a handle may be used.

String keys can be converted to handles using the HandleOf method.  Handles can be converted to keys using the KeyOf method.