--- title: "CacheSize Property Example (JScript) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "JScript" helpviewer_keywords: - "CacheSize property [ADO], JScript example" ms.assetid: 3675f641-b4b1-48ff-ba33-8d9ea064cd04 author: MightyPen ms.author: genemi --- # CacheSize Property Example (JScript) This example uses the [CacheSize](../../../ado/reference/ado-api/cachesize-property-ado.md) property to show the difference in performance for an operation performed with and without a 30-record cache. Cut and paste the following code to Notepad or another text editor, and save it as **CacheSizeJS.asp**. ``` <%@ Language="JScript" %> <%// use this meta tag instead of adojavas.inc%> CacheSize Property Example (JScript)

CacheSize Property Example (JScript)

<% // connection and recordset variables var Cnxn = Server.CreateObject("ADODB.Connection") var strCnxn = "Provider='sqloledb';Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog='Northwind';Integrated Security='SSPI';"; var rsCustomer = Server.CreateObject("ADODB.Recordset"); // caching variables var Now = new Date(); var Start = Now.getTime(); var End, Cache, NoCache try { // open connection Cnxn.Open(strCnxn) // open a recordset on the Employee table using client-side cursor rsCustomer.CursorLocation = adUseClient; rsCustomer.Open("Customers", strCnxn); // loop through the recordset 20 times for (var i=1; i<=20; i++) { rsCustomer.MoveFirst(); while (!rsCustomer.EOF) { // do something with the record var strTemp = new String(rsCustomer("CompanyName")); rsCustomer.MoveNext(); } } Now = new Date(); End = Now.getTime(); NoCache = End - Start; // cache records in groups of 30 rsCustomer.MoveFirst(); rsCustomer.CacheSize = 30; Now = new Date(); Start = Now.getTime(); // loop through the recordset 20 times for (var i=1; i<=20; i++) { rsCustomer.MoveFirst(); while (!rsCustomer.EOF) { // do something with the record var strTemp = new String(rsCustomer("CompanyName")); rsCustomer.MoveNext(); } } Now = new Date(); End = Now.getTime(); var Cache = End - Start; } catch (e) { Response.Write(e.message); } finally { // clean up if (rsCustomer.State == adStateOpen) rsCustomer.Close; if (Cnxn.State == adStateOpen) Cnxn.Close; rsCustomer = null; Cnxn = null; } %>
No Cache 30 Record Cache
<%=NoCache%> <%=Cache%>
``` ## See Also [CacheSize Property (ADO)](../../../ado/reference/ado-api/cachesize-property-ado.md) [Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)