ADO.NET provider for OData / 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, by setting Use Cache to True which is False by default, in the file specified by the Cache Location property of the connection string.

    const string NorthwindSampleUrl = @"Url=";
    static String connectionString = $@"{NorthwindSampleUrl}; Use Cache = true; Cache Tolerance = 500; Cache Location = 'C:\temp\c1cache.db'";
    static void DataReaderSelect()
       Console.WriteLine("Start Time " + DateTime.Now);                  
       using (C1ODataConnection con = new C1ODataConnection(connectionString))
           var cmd = con.CreateCommand();
           cmd.CommandText = "SELECT ProductID,ProductName,UnitPrice from Products limit 10";
           var rdr = cmd.ExecuteReader();
           while (rdr.Read())
              Console.WriteLine(String.Format("\t{0} --> \t\t{1}-->\t\t\t{2}", rdr["ProductID"], rdr["UnitPrice"], rdr["ProductName"]));
           Console.WriteLine("End Time " + DateTime.Now);