ADO.NET provider for Dynamics 365 Sales / Caching
In This Topic
    In This Topic

    Caching data provides various advantages like faster data access and minimizing the calls to API which improves the overall process. The DataConnector supports an easy-to-use caching procedure where several connections can also share the cache.

    User can set necessary connection properties to enable caching feature. For example, Cache Tolerance property that ensures data fetched from the database is the latest version and Cache Location property which is the location in physical drive.

    The default tolerance of the stale data in cache is 600 seconds and the default location is %AppData%/C1DataConnector.

    The below code example implements caching the table, setting Use Cache to True which is False by default, in the file specified by the Cache Location property of the connection string.

    static String connectionString = $@"Url={urlDynamics};Pooling=true;Use Cache=true;Cache Tolerance=6;Cache Location='C:\temp\c1cache.db'; OAuth Client Id={clientID};Username={username};Password={password};OAuth Token Endpoint={tokenEnpoint};OAuth Extend Properties={extendProperties};Max Page Size = 100;";          
    static void Main(string[] args)
      using (C1D365SConnection connection = new C1D365SConnection(connectionString))
        Console.WriteLine("Start Time " + DateTime.Now);
        C1D365SCommand cmd = new C1D365SCommand(connection,"SELECT accountid, Name FROM Accounts Limit 12'");
        var rdr = cmd.ExecuteReader();
        while (rdr.Read())
           Console.WriteLine("Read and cached the row with AccountId " + rdr["AccountId"]);
        Console.WriteLine("End Time " + DateTime.Now);