{"id":8217,"date":"2023-01-26T18:43:07","date_gmt":"2023-01-26T09:43:07","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=8217"},"modified":"2023-02-07T17:07:38","modified_gmt":"2023-02-07T08:07:38","slug":"webservice-cache","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=8217","title":{"rendered":"Web Cache (DataSet)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">OverView : C# WebService 3.5 \uc774\uc0c1 \uc5d0\uc11c Db DataSet Cache \ud654 \ud558\uae30 <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Controller.HttpContext.Cache \uc18d\uc131\uc744 \ud1b5\ud574 \uc774 \ud074\ub798\uc2a4\uc758 \uc778\uc2a4\ud134\uc2a4\ub97c \uac00\uc838\uc62c \uc218 \uc788\uc73c\uba70<br>\uc2f1\uae00\ud1a4 HttpContext.Current.Cache\ub97c \ud1b5\ud574 \uac00\uc838\uc62c \uc218\ub3c4 \uc788\uc2b5\ub2c8\ub2e4.<br>\uc774 \ud074\ub798\uc2a4\ub294 \ub0b4\ubd80\uc801\uc73c\ub85c \ud560\ub2f9\ub41c \ub2e4\ub978 \uce90\uc2f1 \uc5d4\uc9c4\uc744 \uc0ac\uc6a9\ud558\uae30 \ub54c\ubb38\uc5d0 \uba85\uc2dc\uc801\uc73c\ub85c \uc0dd\uc131\ub420 \uac83\uc73c\ub85c \uc608\uc0c1\ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<br>\ucf54\ub4dc\ub97c \uc791\ub3d9\uc2dc\ud0a4\ub294 \uac00\uc7a5 \uac04\ub2e8\ud55c \ubc29\ubc95\uc740 \ub2e4\uc74c\uc744 \uc218\ud589\ud558\ub294 \uac83\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.Simple Source<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:vim decode:true \">public class AccountController : System.Web.Mvc.Controller{ \n  public System.Web.Mvc.ActionResult Index(){\n    List&lt;object&gt; list = new List&lt;Object&gt;();\n\n    HttpContext.Cache[\"ObjectList\"] = list;                 \/\/ add\n    list = (List&lt;object&gt;)HttpContext.Cache[\"ObjectList\"]; \/\/ retrieve\n    HttpContext.Cache.Remove(\"ObjectList\");                 \/\/ remove\n    return new System.Web.Mvc.EmptyResult();\n  }\n}<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.HttpContext.Cache<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"453\" height=\"704\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-5.png\" alt=\"\" class=\"wp-image-8218\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-5.png 453w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-5-193x300.png 193w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3.DB<\/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-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"213\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-6.png\" alt=\"\" class=\"wp-image-8219\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-6.png 388w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-6-300x165.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4.Insert Query<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\ub9c1\ud06c : https:\/\/github.com\/iammukeshm\/RepositoryPatternWithCachingAndHangfire\/blob\/master\/SampleCustomers.sql<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tsql decode:true \">insert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Caressa', 'Walsh', '868-449-3013', 'cwalsh0@google.es', '3\/23\/1996');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Rhea', 'Andrichuk', '733-892-8926', 'randrichuk1@elpais.com', '12\/11\/1997');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Amelia', 'Epp', '247-422-8619', 'aepp2@spiegel.de', '7\/16\/1999');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Cesaro', 'Goodwin', '606-804-3382', 'cgoodwin3@salon.com', '8\/16\/1990');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Lira', 'Crookall', '320-145-2453', 'lcrookall4@g.co', '9\/14\/1996');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Tye', 'Collin', '548-245-2593', 'tcollin5@dailymail.co.uk', '4\/9\/1993');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Clare', 'Kelson', '324-249-1362', 'ckelson6@amazon.co.jp', '11\/26\/1992');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Wilmer', 'Swaite', '657-532-9884', 'wswaite7@addthis.com', '9\/22\/1990');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Delphine', 'Gasson', '392-230-1556', 'dgasson8@51.la', '8\/7\/1994');\ninsert into Customers (FirstName, LastName, Contact, Email, DateOfBirth) values ('Manon', 'Yeowell', '789-838-9532', 'myeowell9@jimdo.com', '10\/11\/1999');<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5.WebService Call<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Services;\nusing System.Data;\nusing System.Data.SqlClient;\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            DataTable dt = CacheClass.GetCustomerDataSet().Tables[0];\n            \/\/ Create an array that will hold the name of each customer.         \n            string[] names = new string[dt.Rows.Count];\n            \/\/ Fill the array.         \n            int i = 0;\n\n            foreach (DataRow row in dt.Rows)\n            {\n                names[i] = row[\"FirstName\"].ToString();\n                i += 1;\n            }\n            return names;\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">6.Cache Insert<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" title=\"CacheClass\">using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Data;\nusing System.Data.SqlClient;\n\nnamespace WebService1\n{\n    public class CacheClass\n    {  \n        private static string connectionString = \"Server=SQLOLEDB.1;Password=******;Persist Security Info=True;User ID=MYID;Initial Catalog=MYDB;Data Source=MYPC\";\n\n        public static DataSet GetCustomerDataSet()\n        {\n            \/\/ Check for cached item.         \n            DataSet ds = HttpContext.Current.Cache[\"Customers\"] as DataSet;\n            if (ds == null)\n            {\n                \/\/ Recreate the item.             \n                string SQL = \"SELECT * FROM Customers\";\n                \/\/ Create ADO.NET objects.             \n                SqlConnection con = new SqlConnection(connectionString);\n                SqlCommand com = new SqlCommand(SQL, con);\n                SqlDataAdapter adapter = new SqlDataAdapter(com);\n                ds = new DataSet();\n                \/\/ Execute the command.             \n                try\n                {\n                    con.Open();\n                    adapter.Fill(ds, \"Customers\");\n                    \/\/ Store the item in the cache (for 60 Minutes).                 \n                    HttpContext.Current.Cache.Insert(\"Customers\", ds, null, DateTime.Now.AddMinutes(60), TimeSpan.Zero);\n                }\n                catch (Exception err)\n                {\n                    System.Diagnostics.Debug.WriteLine(err.ToString());\n                }\n                finally\n                {\n                    con.Close();\n                }\n            }\n            return ds;\n        }\n\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">7.\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\">8.Result<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:xhtml decode:true \">&lt;ArrayOfString xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\" xmlns=\"http:\/\/tempuri.org\/\"&gt;\n&lt;string&gt;Caressa&lt;\/string&gt;\n&lt;string&gt;Rhea&lt;\/string&gt;\n&lt;string&gt;Amelia&lt;\/string&gt;\n&lt;string&gt;Cesaro&lt;\/string&gt;\n&lt;string&gt;Lira&lt;\/string&gt;\n&lt;string&gt;Tye&lt;\/string&gt;\n&lt;string&gt;Clare&lt;\/string&gt;\n&lt;string&gt;Wilmer&lt;\/string&gt;\n&lt;string&gt;Delphine&lt;\/string&gt;\n&lt;string&gt;Manon&lt;\/string&gt;\n&lt;string&gt;Bev&lt;\/string&gt;\n&lt;string&gt;Lodovico&lt;\/string&gt;\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">9.\uc811\uc18d \ud654\uba74 \uc218\uac00 \ub9ce\uc544\uc9c0\uba74 \uba54\ubaa8\ub9ac \uc0ac\uc6a9\ub3c4 \uc62c\ub77c \uac04\ub2e4. (10\ud654\uba74) =&gt; \uc811\uc18d \uc885\ub958 \ub418\uba74 \uc6d0\ub798\ub300\ub85c \ub41c\ub2e4. <\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1023\" height=\"784\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21.png\" alt=\"\" class=\"wp-image-8416\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21.png 1023w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21-300x230.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21-768x589.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-21-660x506.png 660w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">source&nbsp; :&nbsp;https:\/\/stackoverflow.com\/questions\/41684213\/looking-for-a-very-simple-cache-example?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>NET provides a few Cache classes<\/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":[238],"class_list":["post-8217","post","type-post","status-publish","format-standard","hentry","category-memory-cache","tag-cache"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8217","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=8217"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8217\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}