Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



ADO Recordset Object CacheSize Property

The number of records from a Recordset object that are cached locally in memory. This property is not currently supported on UNIX.

CacheSize Property Return Values

Sets or returns a Long value that must be greater than 0. Default is 1.

CacheSize Property Remarks

Use the CacheSize property to control how many records the provider keeps in its buffer and how many to retrieve at one time into local memory. For example, if the CacheSize is 10, after first opening the Recordset object, the provider retrieves the first 10 records into local memory. As you move through the Recordset object, the provider returns the data from the local memory buffer. As soon as you move past the last record in the cache, the provider retrieves the next 10 records from the data source into the cache.

The value of this property can be adjusted during the life of the Recordset object, but changing this value only affects the number of records in the cache after subsequent retrievals from the data source. Changing the property value alone will not change the current contents of the cache.

If there are fewer records to retrieve than CacheSize specifies, the provider returns the remaining records; no error occurs.

A CacheSize setting of zero is not allowed and returns an error.

Records retrieved from the cache don't reflect concurrent changes that other users made to the source data. To force an update of all the cached data, use the ADO Recordset Object Resync Method.

CacheSize Property Example

This Visual Basic example uses the CacheSize property to show the difference in performance for an operation performed with and without a 30-record cache.

Public Sub CacheSizeX() 
Dim rstRoySched As ADODB.Recordset 
Dim strCnn As String 
Dim sngStart As Single 
Dim sngEnd As Single 
Dim sngNoCache As Single 
Dim sngCache As Single 
Dim intLoop As Integer 
Dim strTemp As String
` Open the RoySched table. 
strCnn = "driver={SQL Server};server=srv;" & _ 
"uid=sa;pwd=;database=pubs" 
Set rstRoySched = New ADODB.Recordset 
rstRoySched.Open "roysched", strCnn, , , adCmdTable
` Enumerate the Recordset object twice and record 
` the elapsed time. 
sngStart = Timer
For intLoop = 1 To 2 
rstRoySched.MoveFirst
Do While Not rstRoySched.EOF 
' Execute a simple operation for the performance test. 
strTemp = rstRoySched!title_id 
rstRoySched.MoveNext 
Loop 
Next intLoop
sngEnd = Timer 
sngNoCache = sngEnd - sngStart
' Cache records in groups of 30 records. 
rstRoySched.MoveFirst 
rstRoySched.CacheSize = 30 
sngStart = Timer
` Enumerate the Recordset object twice and record 
' the elapsed time. 
For intLoop = 1 To 2 
rstRoySched.MoveFirst 
Do While Not rstRoySched.EOF 
` Execute a simple operation for the 
` performance test. 
strTemp = rstRoySched!title_id 
rstRoySched.MoveNext 
Loop 
Next intLoop 
sngEnd = Timer 
sngCache = sngEnd - sngStart
' Display performance results. 
MsgBox "Caching Performance Results:" & vbCr & _ 
" No cache: " & Format(sngNoCache, _ 
"##0.000") & " seconds" & vbCr & _ 
" 30-record cache: " & Format(sngCache, _ 
"##0.000") & " seconds" 
rstRoySched.Close 
End Sub


ContentsPreviousNextIndex