{"id":7763,"date":"2022-06-24T18:05:51","date_gmt":"2022-06-24T09:05:51","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=7763"},"modified":"2024-02-19T11:57:06","modified_gmt":"2024-02-19T02:57:06","slug":"c-memory-cache","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=7763","title":{"rendered":"C# Memory Cache"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\uba54\ubaa8\ub9ac \uce90\uc2dc <\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\uc18d\ub3c4 \uc99d\uac00\ub97c \uc704\ud574 \ub514\ube44 \ub370\uc774\ud0c0\ub97c \ubbf8\ub9ac \uba54\ubaa8\ub9ac\uc5d0 \uac00\uc838\uc624\ub294 \ubc29\uc2dd\uc73c\ub85c \ubcc0\uacbd\ud574\uc11c \uc18d\ub3c4\ub97c \ub192\uc774\ub294 \ubc29\uc2dd<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\uc7a5\uc815 Pros<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Database \ud638\ucd9c\uc774 \uc904\uc5b4\ub4e0\ub2e4.<\/li>\n\n\n\n<li>\uc6f9\uc11c\ube44\uc2a4 \ub85c\ub4dc\uac00 \uc904\uc5b4\ub4e0\ub2e4.<\/li>\n\n\n\n<li>\uc6d0\ud558\ub294 \ub370\uc774\ud0c0\ub97c \ube68\ub9ac \ucc3e\uc744\uc218 \uc788\ub2e4.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\ub2e8\uc810 Cons<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\uc720\uc9c0\uad00\ub9ac\uac00 \ub9ce\uc774 \ub4e0\ub2e4.<\/li>\n\n\n\n<li>\uc18c\uc2a4\uac00  \uae38\uc5b4\uc9c0\uace0 \ubcf5\uc7a1\ud574\uc9c4\ub2e4.<\/li>\n\n\n\n<li>\ub370\uc774\ud0c0 \ubca0\uc774\uc2a4\uc640 \uc2f1\ud06c\ub97c \ub9de\ucd94\uae30\uac00 \uc5b4\ub835\ub2e4.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Type<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In-Momory Cache :  \uc9e7\uc740\uc2dc\uac04 \uc0ac\uc6a9\ud558\uae30<\/li>\n\n\n\n<li>\uc601\uad6c Cache  : \uae34\uc2dc\uac04 \uc0ac\uc6a9\ud558\uae30<\/li>\n\n\n\n<li>\ubd84\uc0b0 Cashe : \uc5ec\ub7ec\ud504\ub85c\uc138\uc11c\ub85c \ubd84\uc0b0\ud558\uae30<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\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 \/ \ud604\uc7ac 8.0.0<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"464\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching-1024x464.png\" alt=\"\" class=\"wp-image-7764\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching-1024x464.png 1024w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching-300x136.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching-768x348.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching-1536x696.png 1536w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/06\/System_Runtime_Caching.png 1538w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Sample 1<\/h3>\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 MemChech\n{\n    class Program\n    {\n        static MemoryCache cache = new MemoryCache(\"DEV\");\n        \n        static void Main(string[] args)\n        {\n            var cacheItemPolicy = new CacheItemPolicy\n            {\n                AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60.0)\n            };\n\n            var cacheItem = new CacheItem(\"fullName\", \"Hong Gildong\");\n                       \n            var result = cache.Add(cacheItem, cacheItemPolicy);\n\n            result = cache.Add(\"fullName02\", \"Hong Gildong02\", cacheItemPolicy);\n\n            result = cache.Add(\"fullName03\", \"Hong Gildong03\", DateTimeOffset.Now.AddMinutes(10));\n\n            cache.Set(cacheItem, cacheItemPolicy);\n            cache.Set(\"fullName04\", \"Hong Gildong04\", cacheItemPolicy);\n\n            var isExists = cache.Contains(\"fullName\");\n\n            var value = cache.Get(\"fullName\");\n\n            var getresult = cache.GetCacheItem(\"fullName\");\n\n            var results = cache.GetValues(new string[] { \"fullName\", \"fullName02\", \"fullName03\", \"fullName04\" });\n            foreach (var item in results)\n            {\n                Console.WriteLine($\"{item.Key} : {item.Value}\");\n            }\n\n            var removeresult = cache.Remove(\"fullName\");\n            Console.WriteLine(\"fullName {0}\", removeresult);\n\n            var countresult = cache.GetCount();\n\n            Console.WriteLine(countresult);\n\n            \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n            cache.Add(new CacheItem(\"firstName\", \"Jaimin02\"), cacheItemPolicy);\n            cache.Add(new CacheItem(\"lastName\", \"Shethiya\"), cacheItemPolicy);\n\n            results = cache.GetValues(new string[] { \"firstName\", \"lastName\", \"fullName\" });\n            foreach (var item in results)\n            {\n                Console.WriteLine($\"{item.Key} : {item.Value}\");\n            }\n\n            countresult = cache.GetCount();\n\n            Console.WriteLine(countresult);\n\n            Console.ReadLine();\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:vim decode:true \">fullName : Hong Gildong\nfullName02 : Hong Gildong02\nfullName03 : Hong Gildong03\nfullName04 : Hong Gildong04\nfullName Hong Gildong\n3\nfirstName : Jaimin02\nlastName : Shethiya\n5\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Sample 2<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">private void Page_Load(object sender, System.EventArgs e)\n{\n\tDataSet ds=(DataSet)HttpContext.Current.Cache[\"dataset\"];\n\t\n\tif(ds==null)\n\t{\n\t\tHttpContext.Current.Cache[\"dataset\"]=\n\t\tDAL.DataUtil.GetDataSet(\"server=peterlap;DataBase=Northwind;user id=sa;\",\"Select * from cUstomers\");\n\t}\n\t\n\tds=(DataSet)HttpContext.Current.Cache[\"dataset\"];\n\tDataGrid1.DataSource=ds.Tables[0];\n\tDataGrid1.DataBind();\n\t\n\tDataSet ds2=(DataSet)HttpContext.Current.Cache[\"dataset2\"];\n\t\n\tif(ds2==null)\n\t{\n\t\tHttpContext.Current.Cache[\"dataset2\"]=\n\t\tDAL.DataUtil.GetDataSet(\"server=peterlap;DataBase=Northwind;user id=sa;\",\"Select * from employees\");\n\t}\n\t\n\tds2=(DataSet)HttpContext.Current.Cache[\"dataset2\"];\n\tDataGrid2.DataSource=ds.Tables[0];\n\tDataGrid2.DataBind();\n}\n\n\npublic static DataSet GetDataSet(string strConnString, string strSQL)\n{\n\tSqlConnection cn = new SqlConnection(strConnString);\n\tcn.Open();\n\tSqlCommand cmd =new SqlCommand(strSQL, cn);\n\tSqlDataAdapter da = new SqlDataAdapter(cmd);\n\tDataSet ds = new DataSet();\n\tda.Fill(ds);\n\tcn.Close();\n\treturn ds;\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>\uba54\ubaa8\ub9ac \uce90\uc2dc \uc18d\ub3c4 \uc99d\uac00\ub97c \uc704\ud574 \ub514\ube44 \ub370\uc774\ud0c0\ub97c \ubbf8\ub9ac \uba54\ubaa8\ub9ac\uc5d0 \uac00\uc838\uc624\ub294 \ubc29\uc2dd\uc73c\ub85c \ubcc0\uacbd\ud574\uc11c \uc18d\ub3c4\ub97c \ub192\uc774\ub294 \ubc29\uc2dd \uc7a5\uc815 Pros \ub2e8\uc810 Cons Type \uc124\uce58 NuGet \ud328\uce90\uc9c0 \uad00\ub9ac\uc5d0\uc11c \uc124\uce58 <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=7763\" title=\"C# Memory Cache\">[&#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":[10],"tags":[],"class_list":["post-7763","post","type-post","status-publish","format-standard","hentry","category-devc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7763","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=7763"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7763\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}