{"id":13411810,"url":"https://github.com/erni27/imcache","last_synced_at":"2025-03-14T17:31:09.036Z","repository":{"id":149992169,"uuid":"622653526","full_name":"erni27/imcache","owner":"erni27","description":"A zero-dependency generic in-memory cache Go library","archived":false,"fork":false,"pushed_at":"2024-08-29T19:54:07.000Z","size":166,"stargazers_count":120,"open_issues_count":5,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-30T10:39:53.341Z","etag":null,"topics":["cache","generic","go","golang","in-memory"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erni27.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-02T18:32:04.000Z","updated_at":"2024-08-29T09:26:41.000Z","dependencies_parsed_at":"2023-12-24T07:48:53.906Z","dependency_job_id":"9e752f91-e962-4353-ae36-7f9884d7371b","html_url":"https://github.com/erni27/imcache","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erni27%2Fimcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erni27%2Fimcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erni27%2Fimcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erni27%2Fimcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erni27","download_url":"https://codeload.github.com/erni27/imcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618669,"owners_count":20320273,"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":["cache","generic","go","golang","in-memory"],"created_at":"2024-07-30T20:01:17.160Z","updated_at":"2025-03-14T17:31:08.716Z","avatar_url":"https://github.com/erni27.png","language":"Go","readme":"# imcache\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/erni27/imcache/ci.yaml?branch=master)](https://github.com/erni27/imcache/actions?query=workflow%3ACI)\n[![Go Report Card](https://goreportcard.com/badge/github.com/erni27/imcache)](https://goreportcard.com/report/github.com/erni27/imcache)\n![Go Version](https://img.shields.io/badge/go%20version-%3E=1.18-61CFDD.svg?style=flat-square)\n[![GoDoc](https://pkg.go.dev/badge/mod/github.com/erni27/imcache)](https://pkg.go.dev/mod/github.com/erni27/imcache)\n[![Coverage Status](https://codecov.io/gh/erni27/imcache/branch/master/graph/badge.svg)](https://codecov.io/gh/erni27/imcache)\n\n`imcache` is a zero-dependency generic in-memory cache Go library.\n\nIt supports absolute expiration, sliding expiration, max entries limit, eviction callbacks and sharding. It's safe for concurrent use by multiple goroutines.\n\n```Go\nimport \"github.com/erni27/imcache\"\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/erni27/imcache\"\n)\n\nfunc main() {\n\t// Zero value Cache is a valid non-sharded cache\n\t// with no expiration, no sliding expiration,\n\t// no entry limit and no eviction callback.\n\tvar c imcache.Cache[uint32, string]\n\tc.Set(1, \"one\", imcache.WithNoExpiration())\n\tvalue, ok := c.Get(1)\n\tif !ok {\n\t\tpanic(\"value for the key '1' not found\")\n\t}\n\tfmt.Println(value)\n}\n```\n\n### Expiration\n\n`imcache` supports the following expiration options:\n\n* `WithNoExpiration` - the entry will never expire.\n* `WithExpiration` - the entry will expire after a certain time.\n* `WithExpirationDate` - the entry will expire at a certain date.\n* `WithSlidingExpiration` - the entry will expire after a certain time if it hasn't been accessed. The expiration time is reset every time the entry is accessed. It is slided to now + sliding expiration time when now is the time when the entry was accessed.\n\n```go\n// The entry will never expire.\nc.Set(1, \"one\", imcache.WithNoExpiration())\n// The entry will expire after 1 second.\nc.Set(2, \"two\", imcache.WithExpiration(time.Second))\n// The entry will expire at the given date.\nc.Set(3, \"three\", imcache.WithExpirationDate(time.Now().Add(time.Second)))\n// The entry will expire after 1 second if it hasn't been accessed.\n// Otherwise, the expiration time will slide to the access time + 1 second.\nc.Set(4, \"four\", imcache.WithSlidingExpiration(time.Second))\n```\n\nOne can also use the `WithExpirationOption` and `WithSlidingExpirationOption` options to set the default expiration time for the given cache instance. By default, the default expiration time is set to no expiration.\n\n```go\n// Create a new cache instance with the default expiration time equal to 1 second.\nc1 := imcache.New[int32, string](imcache.WithDefaultExpirationOption[int32, string](time.Second))\n// The entry will expire after 1 second (the default expiration time).\nc1.Set(1, \"one\", imcache.WithDefaultExpiration())\n\n// Create a new cache instance with the default sliding expiration time equal to 1 second.\nc2 := imcache.New[int32, string](imcache.WithDefaultSlidingExpirationOption[int32, string](time.Second))\n// The entry will expire after 1 second (the default expiration time) if it hasn't been accessed.\n// Otherwise, the expiration time will slide to the access time + 1 second.\nc2.Set(1, \"one\", imcache.WithDefaultExpiration())\n```\n\n### Key eviction\n\n`imcache` actively evicts expired entries. It removes expired entries when they are accessed by most of `Cache` methods (both read and write). `Peek`, `PeekMultiple` and `PeekAll` methods are the exception. They don't remove the expired entries and do not slide the expiration time (if the sliding expiration is set).\n\nIt is possible to use the `Cleaner` to periodically remove expired entries from the cache. The `Cleaner` is a background goroutine that periodically removes expired entries from the cache. The `Cleaner` is disabled by default. One can use the `WithCleanerOption` option to enable the `Cleaner` and set the cleaning interval.\n\n```go\n// Create a new Cache with a Cleaner which will remove expired entries every 5 minutes.\nc := imcache.New[string, string](imcache.WithCleanerOption[string, string](5 * time.Minute))\n// Close the Cache. This will stop the Cleaner if it is running.\ndefer c.Close()\n```\n\nTo be notified when the entry is evicted from the cache, one can use the `EvictionCallback`. It's a function that accepts the key and the value of the evicted entry along with the reason why the entry was evicted. One can use the `WithEvictionCallbackOption` option to set the `EvictionCallback` for the given cache instance.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/erni27/imcache\"\n)\n\nfunc LogEvictedEntry(key string, value interface{}, reason imcache.EvictionReason) {\n\tlog.Printf(\"Evicted entry: %s=%v (%s)\", key, value, reason)\n}\n\nfunc main() {\n\tc := imcache.New[string, interface{}](\n\t\timcache.WithDefaultExpirationOption[string, interface{}](time.Second),\n\t\timcache.WithEvictionCallbackOption[string, interface{}](LogEvictedEntry),\n\t)\n\tc.Set(\"foo\", \"bar\", imcache.WithDefaultExpiration())\n\n\ttime.Sleep(time.Second)\n\n\t_, ok := c.Get(\"foo\")\n\tif ok {\n\t\tpanic(\"expected entry to be expired\")\n\t}\n}\n```\n\n`EvictionCallback` is invoked in a separate goroutine to not block any `Cache` method.\n\n### Max entries limit\n\n`imcache` supports setting the max entries limit. When the max entries limit is reached, the entry is evicted according to the chosen eviction policy. `imcache` supports the following eviction policies:\n\n* `EvictionPolicyLRU` - the least recently used entry is evicted.\n* `EvictionPolicyLFU` - the least frequently used entry is evicted.\n* `EvictionPolicyRandom` - a random entry is evicted.\n\nOne can use the `WithMaxEntriesLimitOption` option to set the max entries limit and the eviction policy for the given cache instance.\n\n```go\nc := imcache.New[uint32, string](imcache.WithMaxEntriesLimitOption[uint32, string](1000, imcache.EvictionPolicyLRU))\n```\n\n### Sharding\n\n`imcache` supports sharding. Each shard is a separate `Cache` instance. A shard for a given key is selected by computing the hash of the key and taking the modulus of the number of shards. `imcache` exposes the `Hasher64` interface that wraps `Sum64` accepting a key and returning a 64-bit hash of the input key. It can be used to implement custom sharding algorithms.\n\nA `Sharded` instance can be created by calling the `NewSharded` method.\n\n```go\nc := imcache.NewSharded[string, string](4, imcache.DefaultStringHasher64{})\n```\n\nAll previous examples apply to `Sharded` type as well. Note that `Option`(s) are applied to each shard (`Cache` instance separately) not to the `Sharded` instance itself.\n\n## Performance\n\n`imcache` was compared to the vanilla Go map with simple locking mechanism. The benchmarks were run on an Apple M1 Pro 8-core CPU with 32 GB of RAM running macOS Ventura 13.4.1 using Go 1.21.6.\n\n### Reads\n\n```bash\ngo version\ngo version go1.21.6 darwin/arm64\ngo test -benchmem -bench \"Get_|Get$|Peek_|Peek$\"\ngoos: darwin\ngoarch: arm64\npkg: github.com/erni27/imcache\nBenchmarkCache_Get-8                                                                 2655246\t       428.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/2_Shards-8                                                      2810713\t       436.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/4_Shards-8                                                      2732820\t       444.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/8_Shards-8                                                      2957444\t       445.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/16_Shards-8                                                     2773999\t       447.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/32_Shards-8                                                     2752075\t       443.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/64_Shards-8                                                     2752899\t       439.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get/128_Shards-8                                                    2771691\t       456.3 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyLRU-8                               2410712\t       526.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/2_Shards-8                    2346715\t       543.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/4_Shards-8                    2317453\t       566.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/8_Shards-8                    2293774\t       556.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/16_Shards-8                   2292554\t       557.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/32_Shards-8                   2262634\t       542.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/64_Shards-8                   2318079\t       544.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU/128_Shards-8                  2278434\t       565.6 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyLFU-8                               2482602\t       528.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/2_Shards-8                    2403782\t       534.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/4_Shards-8                    2286364\t       548.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/8_Shards-8                    2239857\t       576.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/16_Shards-8                   2198414\t       556.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/32_Shards-8                   2109063\t       554.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/64_Shards-8                   2251125\t       550.6 ns/op\t      23 B/op\t       2 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU/128_Shards-8                  2172662\t       551.0 ns/op\t      23 B/op\t       2 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyRandom-8                            2959924\t       433.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/2_Shards-8                 2909020\t       429.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/4_Shards-8                 2890734\t       438.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/8_Shards-8                 2947471\t       432.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/16_Shards-8                2937757\t       456.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/32_Shards-8                2963146\t       427.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/64_Shards-8                2794441\t       430.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom/128_Shards-8               2965760\t       466.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Peek-8                                                                3034557\t       419.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/2_Shards-8                                                     2907327\t       452.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/4_Shards-8                                                     2918097\t       441.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/8_Shards-8                                                     2923375\t       442.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/16_Shards-8                                                    2927227\t       443.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/32_Shards-8                                                    2843028\t       439.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/64_Shards-8                                                    2898458\t       461.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek/128_Shards-8                                                   2805452\t       460.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkMap_Get-8                                                                   4693522\t       327.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Get_Parallel-8                                                        2272208\t       546.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/2_Shards-8                                             3216616\t       416.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/4_Shards-8                                             3898989\t       327.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/8_Shards-8                                             5443684\t       241.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/16_Shards-8                                            6995467\t       186.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/32_Shards-8                                            8505585\t       154.6 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/64_Shards-8                                            10256752\t       170.9 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_Parallel/128_Shards-8                                           12003910\t       113.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel-8                      1995304\t       627.3 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/2_Shards-8           2628376\t       474.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/4_Shards-8           3056476\t       407.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/8_Shards-8           4281996\t       304.3 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/16_Shards-8          5438091\t       237.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/32_Shards-8          6442630\t       209.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/64_Shards-8          8096386\t       177.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLRU_Parallel/128_Shards-8         9417211\t       137.3 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel-8                      1463374\t       796.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/2_Shards-8           2112945\t       591.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/4_Shards-8           3008568\t       412.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/8_Shards-8           4302746\t       296.3 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/16_Shards-8          5671981\t       231.8 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/32_Shards-8          6828380\t       186.5 ns/op\t      23 B/op\t       2 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/64_Shards-8          7074661\t       161.5 ns/op\t      23 B/op\t       2 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyLFU_Parallel/128_Shards-8         9294237\t       139.2 ns/op\t      23 B/op\t       2 allocs/op\nBenchmarkCache_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel-8                   1838180\t       675.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/2_Shards-8        2781007\t       455.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/4_Shards-8        4072056\t       341.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/8_Shards-8        5529966\t       227.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/16_Shards-8       7354364\t       211.7 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/32_Shards-8       8624466\t       138.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/64_Shards-8       11442829\t       161.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Get_MaxEntriesLimit_EvictionPolicyRandom_Parallel/128_Shards-8      12071902\t       104.4 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkCache_Peek_Parallel-8                                                       7957777\t       155.1 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/2_Shards-8                                            7781154\t       163.5 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/4_Shards-8                                           12301404\t       112.0 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/8_Shards-8                                           12828216\t       106.2 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/16_Shards-8                                          13837890\t       94.11 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/32_Shards-8                                          14921073\t       89.67 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/64_Shards-8                                          15708536\t       87.81 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkSharded_Peek_Parallel/128_Shards-8                                         16547871\t       84.76 ns/op\t      23 B/op\t       1 allocs/op\nBenchmarkMap_Get_Parallel-8                                                          3098846\t       453.0 ns/op\t      23 B/op\t       1 allocs/op\nPASS\nok  \tgithub.com/erni27/imcache\t366.377s\n```\n\n### Writes\n\n```bash\ngo version\ngo version go1.21.6 darwin/arm64\ngo test -benchmem -bench \"_Set\"\ngoos: darwin\ngoarch: arm64\npkg: github.com/erni27/imcache\nBenchmarkCache_Set-8                                                                 2942062\t       461.7 ns/op\t     161 B/op\t       2 allocs/op\nBenchmarkSharded_Set/2_Shards-8                                                      2939275\t       487.5 ns/op\t     162 B/op\t       2 allocs/op\nBenchmarkSharded_Set/4_Shards-8                                                      2827146\t       497.1 ns/op\t     166 B/op\t       2 allocs/op\nBenchmarkSharded_Set/8_Shards-8                                                      2837316\t       509.1 ns/op\t     165 B/op\t       2 allocs/op\nBenchmarkSharded_Set/16_Shards-8                                                     2818513\t       495.7 ns/op\t     166 B/op\t       2 allocs/op\nBenchmarkSharded_Set/32_Shards-8                                                     2793490\t       506.3 ns/op\t     167 B/op\t       2 allocs/op\nBenchmarkSharded_Set/64_Shards-8                                                     2815544\t       499.7 ns/op\t     166 B/op\t       2 allocs/op\nBenchmarkSharded_Set/128_Shards-8                                                    2738779\t       511.2 ns/op\t     170 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyLRU-8                               3217950\t       423.2 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/2_Shards-8                    2893335\t       458.4 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/4_Shards-8                    2940762\t       460.9 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/8_Shards-8                    2976267\t       462.5 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/16_Shards-8                   2849967\t       478.1 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/32_Shards-8                   2859116\t       472.2 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/64_Shards-8                   2842370\t       466.6 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU/128_Shards-8                  2863222\t       481.6 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyLFU-8                               3198320\t       417.6 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/2_Shards-8                    2944507\t       450.2 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/4_Shards-8                    2915707\t       456.9 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/8_Shards-8                    2820458\t       464.4 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/16_Shards-8                   2833208\t       479.6 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/32_Shards-8                   2864629\t       460.9 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/64_Shards-8                   2846596\t       491.7 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU/128_Shards-8                  2841228\t       493.6 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyRandom-8                            2988330\t       459.8 ns/op\t      59 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/2_Shards-8                 2713388\t       495.6 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/4_Shards-8                 2756364\t       493.7 ns/op\t      58 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/8_Shards-8                 2691565\t       484.5 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/16_Shards-8                2710840\t       479.6 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/32_Shards-8                2728695\t       496.0 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/64_Shards-8                2690887\t       507.6 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom/128_Shards-8               2663871\t       495.1 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkMap_Set-8                                                                   5847526\t       339.0 ns/op\t     106 B/op\t       2 allocs/op\nBenchmarkCache_Set_Parallel-8                                                        2347249\t       527.7 ns/op\t     123 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/2_Shards-8                                             3112208\t       444.3 ns/op\t     156 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/4_Shards-8                                             3323001\t       401.2 ns/op\t     149 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/8_Shards-8                                             4130948\t       291.3 ns/op\t     131 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/16_Shards-8                                            5516203\t       274.4 ns/op\t     169 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/32_Shards-8                                            6069385\t       219.0 ns/op\t     158 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/64_Shards-8                                            7290878\t       187.9 ns/op\t     141 B/op\t       2 allocs/op\nBenchmarkSharded_Set_Parallel/128_Shards-8                                           8021259\t       163.6 ns/op\t     133 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel-8                      2402929\t       555.8 ns/op\t      66 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/2_Shards-8           2835458\t       418.2 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/4_Shards-8           3219746\t       393.8 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/8_Shards-8           4225972\t       301.9 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/16_Shards-8          5186444\t       246.7 ns/op\t      67 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/32_Shards-8          6100933\t       222.6 ns/op\t      70 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/64_Shards-8          7518198\t       180.7 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLRU_Parallel/128_Shards-8         8257630\t       180.1 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel-8                      2344273\t       543.1 ns/op\t      66 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/2_Shards-8           2973801\t       442.6 ns/op\t      69 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/4_Shards-8           3416180\t       383.2 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/8_Shards-8           4511509\t       293.7 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/16_Shards-8          5374215\t       230.7 ns/op\t      68 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/32_Shards-8          6602998\t       205.1 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/64_Shards-8          7730086\t       171.8 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyLFU_Parallel/128_Shards-8         8232051\t       154.6 ns/op\t      65 B/op\t       2 allocs/op\nBenchmarkCache_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel-8                   2186001\t       592.0 ns/op\t      55 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/2_Shards-8        2716564\t       438.3 ns/op\t      57 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/4_Shards-8        3548733\t       366.0 ns/op\t      55 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/8_Shards-8        4665452\t       296.7 ns/op\t      55 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/16_Shards-8       6088111\t       240.0 ns/op\t      59 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/32_Shards-8       7442355\t       197.1 ns/op\t      55 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/64_Shards-8       8089219\t       163.0 ns/op\t      55 B/op\t       2 allocs/op\nBenchmarkSharded_Set_MaxEntriesLimit_EvictionPolicyRandom_Parallel/128_Shards-8      9815180\t       144.8 ns/op\t      56 B/op\t       2 allocs/op\nBenchmarkMap_Set_Parallel-8                                                          3541270\t       407.3 ns/op\t      92 B/op\t       2 allocs/op\nPASS\nok  \tgithub.com/erni27/imcache\t135.166s\n```\n","funding_links":[],"categories":["数据库","Database","Data Integration Frameworks"],"sub_categories":["缓存","Caches"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferni27%2Fimcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferni27%2Fimcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferni27%2Fimcache/lists"}