{"id":20500968,"url":"https://github.com/caesay/genericmemorycache","last_synced_at":"2025-07-18T10:33:01.337Z","repository":{"id":117003970,"uuid":"48513194","full_name":"caesay/GenericMemoryCache","owner":"caesay","description":"System.Runtime.Caching.Generic","archived":false,"fork":false,"pushed_at":"2015-12-23T22:47:21.000Z","size":45,"stargazers_count":3,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T19:17:48.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caesay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-23T22:11:19.000Z","updated_at":"2023-07-07T15:01:54.000Z","dependencies_parsed_at":"2023-04-13T19:47:45.792Z","dependency_job_id":null,"html_url":"https://github.com/caesay/GenericMemoryCache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/caesay/GenericMemoryCache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FGenericMemoryCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FGenericMemoryCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FGenericMemoryCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FGenericMemoryCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caesay","download_url":"https://codeload.github.com/caesay/GenericMemoryCache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FGenericMemoryCache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265742309,"owners_count":23820825,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T18:23:36.689Z","updated_at":"2025-07-18T10:33:01.318Z","avatar_url":"https://github.com/caesay.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"About\n-----\n\nThis fork serves the primary purpose of hosting the following nuget package:\n```\nPM\u003e Install-Package System.Runtime.Caching.Generic\n```\nCommits from the original author, along with my own improvements will be merged here.\n\n\nSystem.Runtime.Caching.Generic\n==============================\n\n* \u003ca href=\"#Overview\"\u003eOverview\u003c/a\u003e\n* \u003ca href=\"#Sample\"\u003eSample use\u003c/a\u003e\n* \u003ca href=\"#ObjectModel\"\u003eObject model\u003c/a\u003e\n\n\u003ca name=\"Overview\"\u003e\u003c/a\u003e\n\nOverview\n--------\n\nThis is a lightweight, strongly-typed, generic, extensible, and thread-safe, [N-way set-associative](https://en.wikipedia.org/wiki/CPU_cache#Associativity), in-process (memory) cache, coming with 4 built-in eviction / replacement policies ([LRU, MRU, LFU](https://en.wikipedia.org/wiki/Cache_algorithms#Examples), none).\n\nThe TestApp console application accompanying the library comes with a few (NUnit) tests wrt. correctness, robustness, and extensibility, along with a basic comparative performance / stress test vs. Microsoft's System.Runtime.Caching introduced in .NET 4.0.\n\n**Please read and accept** the terms of the [LICENSE](https://raw.githubusercontent.com/ysharplanguage/GenericMemoryCache/master/LICENSE.md), or else, do not use this library *as-is*.\n\n\u003ca name=\"Sample\"\u003e\u003c/a\u003e\n\nSample use\n----------\n\n        [Test]\n        // LFU: Least Frequently Used\n        public void Test_BasicLFUCacheSemantic()\n        {\n            var lfuCache = new MemoryCache\u003cint, string\u003e();\n            lfuCache.SetPolicy(typeof(LfuEvictionPolicy\u003c,\u003e));\n            \n            // Note the default number of ways is 1, and the default capacity is 16...\n            Assert.AreEqual(lfuCache.Capacity, AbstractCache.DefaultCapacity);\n\n            var data =\n                Enumerable.Range(0, AbstractCache.DefaultCapacity + 1).\n                Aggregate(new StringBuilder(), (sb, i) =\u003e sb.Append(i \u003e 0 ? String.Format(\",String {0}\", i) : String.Empty)).\n                ToString().\n                Split(',');\n\n            // Cache all the (16) non-empty strings\n            for (var i = 1; i \u003c data.Length; i++)\n            {\n                lfuCache.Add(i, data[i]);\n            }\n\n            // Use all the (16) non-empty strings four times...\n            for (var use = 1; use \u003c= 4; use++)\n            {\n                for (var i = 1; i \u003c data.Length; i++)\n                {\n                    // ... except for \"String 3\", used only twice...\n                    if (i == 3)\n                    {\n                        if (use \u003c= 2)\n                        {\n                            var s = lfuCache.Get(i);\n                        }\n                    }\n                    // ... and for \"String 9\", used only once\n                    else if (i == 9)\n                    {\n                        if (use \u003c= 1)\n                        {\n                            var s = lfuCache.Get(i);\n                        }\n                    }\n                    else\n                    {\n                        var s = lfuCache.Get(i);\n                    }\n                }\n            }\n\n            lfuCache.Add(17, \"String 17\");\n            Assert.AreEqual(lfuCache.Contains(9), false);\n            Assert.AreEqual(lfuCache.Contains(17), true);\n\n            var used4times = lfuCache.Get(17);\n            used4times = lfuCache.Get(17);\n            used4times = lfuCache.Get(17);\n            used4times = lfuCache.Get(17);\n\n            lfuCache.Put(18, \"String 18\");\n            Assert.AreEqual(lfuCache.Contains(3), false);\n            Assert.AreEqual(lfuCache.Contains(17), true);\n            Assert.AreEqual(lfuCache.Contains(18), true);\n        }\n\t\t\n\u003ca name=\"ObjectModel\"\u003e\u003c/a\u003e\n\nObject model\n------------\n\n![System.Runtime.Caching.Generic][System.Runtime.Caching.Generic.png]\n\n[System.Runtime.Caching.Generic.png]: http://i.imgur.com/Wj7yl0s.png \"System.Runtime.Caching.Generic\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesay%2Fgenericmemorycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaesay%2Fgenericmemorycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesay%2Fgenericmemorycache/lists"}