APGen Documentation Previous Topic: ASPCache.FlushInterval Next Topic: ASPCache.Exists() Parent Topic: ASPCache Object    ASPCache Object
ASPCache.Add()
See Also:

Adds an item to the cache.

Syntax

VBScript:

bAdded = Cache.Add( key, value [, expireTime ] )

JScript:

bAdded = Cache.Add( key, value [, expireTime ] );

Object

Cache An ASPCache object.

Parameters

key A string key used to store and lookup the new item.
value The value to be stored in the cache.  This parameter is a Variant, so any data type may be used.
expireTime Optional.  The expiration period for this item.  If no value is specified, the item will not expire.

Return Value

bAdded True if the item was successfully added.  False if the key already exists in the cache.

Notes

The Add method will fail if the specified key already exists in the cache.  If you want to add or overwrite an item regardless of whether it is already present, use the Item property.

This example overwrites an existing item in the cache if it can't be added.  One reason you might want to do this is to avoid overwriting the item's expiration period.

' Assume these variables are already initialized
Dim sKey, vValue, tExpire

' Add the item to the cache
Dim bAdded
bAdded = Cache.Add( sKey, vValue, tExpire )

' If the item could not be added, it already exists
If (Not bAdded) Then

     ' Overwrite the value
     Cache( sKey ) = vValue

End If