Caching Automatically
With Auto Cache the RSSBus SharePoint ADO.NET Provider will automatically load data into the cache database each time you execute a SELECT statement. Each row returned by the query will be inserted or updated into the corresponding table in the cache database.
This is handled in a streaming fashion: each row is processed into the cache database from the original result set as you read the row from the returned SharePointDataReader object so the data is not loaded twice. Any rows you do not read from the returned DataReader will not be updated in the cache.
Tip: When using Auto Cache, ensure you always read all rows from the returned SharePointDataReader.
When using Auto Cache, statements other than SELECT will be executed against the real data table, and not against the cache. This can cause the data in the cache to become out of date.
To access data in the cache with Auto Cache enabled, you need to use the pseudo-table name <table>#Cache. For example, to query the Calendar table in the cache, execute a "SELECT * FROM [Calendar#Cache]" statement.
Note: If you run non-SELECT statements on a table_name#Cache table, the changes will not be replicated on the real data source. You will need to keep track of any changes that you make to the cache if you want to keep them in sync with the real data source.
Cache the Calendars Table
The following example caches data in the .db file specified by the "Cache Location" property of the connection string. The database contains the Accounts table which is populated with the data from the SharePoint data source.String connectionString = "Cache Location=C:\\cache.db;" +
"Auto Cache=true;" +
"Offline=false;" +
"user=myuseraccount;password=mypassword;URL=http://sharepointserver/mysite;";
SharePointConnection connection = new SharePointConnection(connectionString);
SharePointCommand cmd = new SharePointCommand("SELECT * FROM Calendars", connection);
SharePointDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
Console.WriteLine("Read and cached the row with ID " + rdr["Id"]);
}
connection.Close();