{"id":8477,"date":"2023-02-21T14:01:41","date_gmt":"2023-02-21T05:01:41","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=8477"},"modified":"2023-02-21T15:11:17","modified_gmt":"2023-02-21T06:11:17","slug":"memory-cache-3-tables-and-linq-query","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=8477","title":{"rendered":"Memory Cache (3 tables and LINQ Query)"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview:  DataSet\uc744  \uc774\uc6a9\ud558\uc5ec \uad00\uacc4\ud615\uc73c\ub85c Table 3\uac1c\ub97c \uce90\uc2f1\ud574\ubcf8\ub2e4.<\/h3>\n\n\n\n<h2 class=\"wp-block-heading\">1.Net Framework 4.6 \uc774\uc0c1\uc5d0\uc11c \uc124\uce58\uac00\ub2a5<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"577\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png\" alt=\"\" class=\"wp-image-8234\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png 910w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-300x190.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-768x487.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-660x418.png 660w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2.\uc124\uce58<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">NuGet \ud328\uce90\uc9c0 \uad00\ub9ac\uc5d0\uc11c \uc124\uce58 \ubc0f \ucc38\uc870 \ucd94\uac00 \ud655\uc778<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"602\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png\" alt=\"\" class=\"wp-image-8233\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png 902w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-300x200.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-768x513.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-660x440.png 660w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3.\ucc38\uc870 \ud655\uc778<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"531\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png\" alt=\"\" class=\"wp-image-8243\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png 327w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11-185x300.png 185w\" sizes=\"auto, (max-width: 327px) 100vw, 327px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Simple Source<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" title=\"System.Runtime.Caching.MemoryCache\" >using (SqlConnection conn = new SqlConnection(connectionString))\n{\n\tstring SQL = \"SELECT Account_ID, Account_Number, Balance FROM [Bank].[dbo].[Account]\";\n\tSqlCommand com = new SqlCommand(SQL, conn);\n\tSqlDataAdapter adapter = new SqlDataAdapter(com);\n\tconn.Open();\n\tadapter.Fill(ds, \"Account\");\n\t\/\/\/\/\n\tSQL = \"SELECT IDX, Account_ID, Amount, New_Balance, Transaction_Date FROM [Bank].[dbo].[Transaction]\";\n\tcom = new SqlCommand(SQL, conn);\n\tadapter = new SqlDataAdapter(com);\n\tadapter.Fill(ds, \"Transaction\");\n\t\/\/\/\n\tSQL = \"SELECT IDX,Account_ID,Name,Mobile,Regi_Date FROM [Bank].[dbo].[CustomerDetails]\";\n\tcom = new SqlCommand(SQL, conn);\n\tadapter = new SqlDataAdapter(com);\n\tadapter.Fill(ds, \"CustomerDetails\");\n\n\tDataRelation relation = ds.Relations.Add(\"Relation\",\n\t  ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n\t  ds.Tables[\"Transaction\"].Columns[\"Account_ID\"]);\n\n\tDataRelation relation2 = ds.Relations.Add(\"Relation2\",\n\t  ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n\t  ds.Tables[\"CustomerDetails\"].Columns[\"Account_ID\"]);\n\n\t\/\/conn.Close();\n\t\/\/conn.Dispose();\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Process diagram<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png\"><img loading=\"lazy\" decoding=\"async\" width=\"633\" height=\"696\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png\" alt=\"\" class=\"wp-image-8480\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png 633w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32-273x300.png 273w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">6.DB<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"599\" height=\"490\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png\" alt=\"\" class=\"wp-image-8481\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png 599w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33-300x245.png 300w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">7.WebService Call (DataSet)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"488\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-1024x488.png\" alt=\"\" class=\"wp-image-8483\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-1024x488.png 1024w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-300x143.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-768x366.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-660x314.png 660w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34.png 1403w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System.Web.Services;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Collections.Generic;\nusing System.Linq;\n \nnamespace WebService1\n{   \n    public class Service1 : System.Web.Services.WebService\n    {\n \n        [WebMethod()]\n        public DataSet GetProductCatalog()\n        {\n            \/\/ Return the complete DataSet (from the cache, if possible).         \n            \/\/return Function.GetCache();\n            return CacheClass.GetCustomerDataSet();\n        }\n \n [WebMethod()]\n        public string[] GetProductList()\n        {\n            \/\/ Get the customer table (from the cache if possible).         \n            DataSet ds = CacheClass.GetCustomerDataSet();\n\n            IEnumerable&lt;DataRow&gt; result = (from Account in ds.Tables[\"Account\"].AsEnumerable()\n                                           join Transaction in ds.Tables[\"Transaction\"].AsEnumerable()\n                                           on new { Account_ID = Account[\"Account_ID\"] } equals new { Account_ID = Transaction[\"Account_ID\"] }\n                                           where Account.Field&lt;int&gt;(\"Account_ID\") == 1\n                                           select Account);\n\n            \/\/ Create an array that will hold the name of each customer.         \n            string[] names = new string[result.Count()];\n            \/\/ Fill the array.         \n            int i = 0;\n\n            foreach (DataRow row in result)\n            {\n                names[i] = row[\"Account_Number\"].ToString();\n                i += 1;\n            }\n            return names;\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">8.Cache Insert (DataSet)<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" >using System;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Runtime.Caching;\n\nnamespace WebService1\n{\n    public class CacheClass\n    {\n        private static string _key = \"Customers\";\n        private static readonly MemoryCache _cache = MemoryCache.Default;\n\n        \/\/private static string connectionString = \"Data Source=localhost;\" + \"Initial Catalog=Northwind;user ID=sa\";\n        private static string connectionString = \"Server=SQLOLEDB.1;Password=*******;Persist Security Info=True;User ID=MYID;Initial Catalog=MYDB;Data Source=MYCOM\";\n\n        public static DataSet GetCustomerDataSet()\n        {\n             if (!(_cache.Get(_key) is DataSet ds))\n            {\n                ds = new DataSet();\n\n                \/\/ Execute the command.             \n                try\n                {\n                    using (SqlConnection conn = new SqlConnection(connectionString))\n                    {\n                        string SQL = \"SELECT Account_ID, Account_Number, Balance FROM [Bank].[dbo].[Account]\";\n                        SqlCommand com = new SqlCommand(SQL, conn);\n                        SqlDataAdapter adapter = new SqlDataAdapter(com);\n                        conn.Open();\n                        adapter.Fill(ds, \"Account\");\n                        \/\/\/\/\n                        SQL = \"SELECT IDX, Account_ID, Amount, New_Balance, Transaction_Date FROM [Bank].[dbo].[Transaction]\";\n                        com = new SqlCommand(SQL, conn);\n                        adapter = new SqlDataAdapter(com);\n                        adapter.Fill(ds, \"Transaction\");\n                        \/\/\/\n                        SQL = \"SELECT IDX,Account_ID,Name,Mobile,Regi_Date FROM [Bank].[dbo].[CustomerDetails]\";\n                        com = new SqlCommand(SQL, conn);\n                        adapter = new SqlDataAdapter(com);\n                        adapter.Fill(ds, \"CustomerDetails\");\n\n                        DataRelation relation = ds.Relations.Add(\"Relation\",\n                          ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n                          ds.Tables[\"Transaction\"].Columns[\"Account_ID\"]);\n\n                        DataRelation relation2 = ds.Relations.Add(\"Relation2\",\n                          ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n                          ds.Tables[\"CustomerDetails\"].Columns[\"Account_ID\"]);\n\n\n                        \/\/conn.Close();\n                        \/\/conn.Dispose();\n\n                    }\n\n                    var cacheItemPolicy = new CacheItemPolicy()\n                    {\n                        \/\/Set your Cache expiration.\n                        AbsoluteExpiration = DateTime.Now.AddMinutes(60)\n                    };\n\n                    _cache.Add(_key, ds, cacheItemPolicy);\n\n                }\n                catch (Exception err)\n                {\n                    System.Diagnostics.Debug.WriteLine(err.ToString());\n                }\n\n            }\n            return _cache.Get(_key) as DataSet;\n        }\n\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">9.\ub514\ubc84\uadf8 ds<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"342\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png\" alt=\"\" class=\"wp-image-8464\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png 820w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-300x125.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-768x320.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-660x275.png 660w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">10.\ud654\uba74<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" width=\"527\" height=\"177\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-7.png\" alt=\"\" class=\"wp-image-8220\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-7.png 527w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-7-300x101.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">11.Result<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"688\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28.png\" alt=\"\" class=\"wp-image-8463\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28.png 875w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28-300x236.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28-768x604.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-28-660x519.png 660w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Overview: DataSet\uc744 \uc774\uc6a9\ud558\uc5ec \uad00\uacc4\ud615\uc73c\ub85c Table 3\uac1c\ub97c \uce90\uc2f1\ud574\ubcf8\ub2e4. 1.Net Framework 4.6 \uc774\uc0c1\uc5d0\uc11c \uc124\uce58\uac00\ub2a5 2.\uc124\uce58 NuGet \ud328\uce90\uc9c0 \uad00\ub9ac\uc5d0\uc11c \uc124\uce58 \ubc0f \ucc38\uc870 \ucd94\uac00 \ud655\uc778 3.\ucc38\uc870 \ud655\uc778 4. Simple <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=8477\" title=\"Memory Cache (3 tables and LINQ Query)\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[237],"tags":[],"class_list":["post-8477","post","type-post","status-publish","format-standard","hentry","category-memory-cache"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8477"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8477\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}