DataConnector | ComponentOne
ADO.NET provider for Kintone / Caching
In This Topic
    Caching
    In This Topic

    Caching data offers several advantages that can improve overall process performance, including reduced API requests and faster data access.

    The ADO.NET provider features an easy-to-use caching procedure that can also be shared by multiple connections. This article demonstrates the two types of caches that are currently supported:

    To enable the caching feature, necessary connection properties are available, such as:

    Internal caching

    The following code demonstrates how to enable caching for a table by setting the UseCache property to True (by default, it is set to False). The cached data is stored in the file specified by the CacheLocation property in the connection string. For more information on Incremental Caching, refer to this topic.

    C#
    Copy Code
    static void LocalCache()
    {
        const string Username = "********";
        const string Password = "********";
        const string Url = "https://*****.kintone.com";
    
        string kintoneConnection = string.Format("Username={0};Password={1};Url={2};", Username, Password, Url);        
        string connectionString = $"{kintoneConnection};Use Cache = true; Cache Tolerance = 500; Cache Location = 'C:\temp\c1cache.db';";
    
        Console.WriteLine("Start Time " + DateTime.Now);
        using (C1KintoneConnection conn = new C1KintoneConnection(connectionString))
        {
            conn.Open();
            var cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT * FROM Products";
            var rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                Console.WriteLine(String.Format("\t{0} --> \t\t{1}-->\t\t\t{2}", rdr["ProductName"], rdr["Updated By"], rdr["UnitPrice"]));
            }
            Console.WriteLine("End Time " + DateTime.Now);
        }
    }
      
    

    External Caching

    The ADO.NET provider for Kintone supports external caching, allowing users to store cached data in a separate database. This external database serves as a constant repository and can be accessed by multiple connection objects simultaneously. It includes all tables exposed by the Kintone provider and offers configuration options specific to the cache provider.

    To utilize external caching, the provider supports a specified cache, such as SQL Server. You can specify the connection string using the UseCache, CacheProvider, and CacheConnection keys to enable external caching.

    Note: With SQL Server, Cache Provider = ‘Microsoft.Data.SqlClient’ is mandatory so you must create your database as our cache doesn’t create a new Database.

    The following code example implements external caching, by setting Use Cache to True and using 'Microsoft.Data.SqlClient' as the cache provider.

    C#
    Copy Code
    static void ExternalCache()
    {
        const string Username = "youruserid";
        const string Password = "yourpassword";
        const string Url = @"http://****/****/****";
    
        string kintoneConnection = string.Format("Username={0};Password={1};Url={2};", Username, Password, Url);
        string connectionString = $@"{kintoneConnection};Use Cache = true; Cache provider='Microsoft.Data.SqlClient'; 
                                    Cache connection='Server= yourserverid; Database= databasename; User Id= yourId; Password= yourpassword;'";
    
        Console.WriteLine("Start Time " + DateTime.Now);
        using (C1KintoneConnection con = new C1KintoneConnection(connectionString))
        {
            con.Open();
            var cmd = con.CreateCommand();
            cmd.CommandText = "SELECT * FROM Products";
            var rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                Console.WriteLine(String.Format("\t{0} --> \t\t{1}-->\t\t\t{2}", rdr["ProductName"], rdr["Updated By"], rdr["UnitPrice"]));
            }
            Console.WriteLine("End Time " + DateTime.Now);
        }
    }