ADO.NET Provider for WooCommerce

Build 20.0.7587

Caching Metadata

This section describes how to enable caching metadata and how to update the metadata cache.

Before being able to query data, the connector requires relevant metadata to be retrieved. By default, metadata is cached in memory and shared across connections. But if you want to persist across processes, or if metadata requests are expensive, the solution is to cache the metadata to disk.

Enable Caching Metadata

To enable caching of metadata, set CacheMetadata = true and see Configuring the Cache Connection for instructions on how to configure your connection string. The provider caches the metadata the first time it is needed and uses the metadata cache for subsequent requests.

Update the Metadata Cache

Because metadata is cached, changes to metadata on the live source, for example, adding or removing a column or attribute, are not automatically reflected in the metadata cache. To get updates to the live metadata, you need to delete or drop the cached data.

Cache Metadata from Code

The following code can be used to build the metadata cache. This is especially useful when using the data provider in Entity Framework.

C#

String connectionString = "Cache Location=C:\\cache.db;Cache MetaData=True; Url=http://localhost/wordpress/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;";
using (WooCommerceConnection conn = new WooCommerceConnection(connectionString)) {
  conn.Open();
  DataTable table = conn.GetSchema("Tables");
  Console.WriteLine("Total number of tables found: " + table.Rows.Count);

  foreach (DataRow row in databaseSchema.Rows) {
    foreach (DataColumn column in databaseSchema.Columns) {
      Console.WriteLine(row[column]);
    }
  }
  Console.WriteLine();
  Console.WriteLine("All tables cached.");
}

VB.NET

Dim connectionString As String = "Cache Location=C:\\cache.db;Cache MetaData=True; Url=http://localhost/wordpress/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;"
Using conn As New WooCommerceConnection(connectionString)
  conn.Open()
  Dim databaseSchema As DataTable = conn.GetSchema("Tables")
  Console.WriteLine("Total number of tables found: " + databaseSchema.Rows.Count.ToString())

  For Each row As DataRow In databaseSchema.Rows
    For Each column As DataColumn In databaseSchema.Columns
      Console.WriteLine(row(column))
    Next
  Next
  Console.WriteLine()
  Console.WriteLine("All tables cached.")
  Console.ReadKey()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587