{"id":42750844,"url":"https://github.com/bool64/cache","last_synced_at":"2026-01-29T19:33:32.477Z","repository":{"id":37797802,"uuid":"365869178","full_name":"bool64/cache","owner":"bool64","description":"High performance resilient in-memory cache for Go","archived":false,"fork":false,"pushed_at":"2025-11-01T09:14:36.000Z","size":198,"stargazers_count":25,"open_issues_count":6,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-01T11:18:22.766Z","etag":null,"topics":["cache","cache-stampede","cachemanager","go","resiliency"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/bool64/cache","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/bool64.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-05-09T23:35:40.000Z","updated_at":"2025-10-29T07:17:00.000Z","dependencies_parsed_at":"2023-12-26T00:27:38.823Z","dependency_job_id":"c4d52b6c-b97c-4ed2-b7b6-fe651cf0b393","html_url":"https://github.com/bool64/cache","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":"bool64/go-template","purl":"pkg:github/bool64/cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bool64%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bool64%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bool64%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bool64%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bool64","download_url":"https://codeload.github.com/bool64/cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bool64%2Fcache/sbom","scorecard":{"id":247854,"data":{"date":"2025-08-11","repo":{"name":"github.com/bool64/cache","commit":"18e292f9a3b9e5669df7b2dcdb444c20f6c4c6a2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.1,"checks":[{"name":"Code-Review","score":1,"reason":"Found 4/21 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/bench.yml:1","Warn: no topLevel permission defined: .github/workflows/cloc.yml:1","Warn: no topLevel permission defined: .github/workflows/golangci-lint.yml:1","Warn: no topLevel permission defined: .github/workflows/gorelease.yml:1","Warn: no topLevel permission defined: .github/workflows/test-unit.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/bench.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/bench.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/bench.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/bench.yml:64: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/bench.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/bench.yml:114: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/bench.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cloc.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/cloc.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cloc.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/cloc.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/cloc.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/cloc.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/golangci-lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/golangci-lint.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gorelease.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/gorelease.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/gorelease.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/gorelease.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-unit.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-unit.yml:107: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-unit.yml:133: update your workflow using https://app.stepsecurity.io/secureworkflow/bool64/cache/test-unit.yml/master?enable=pin","Warn: goCommand not pinned by hash: .github/workflows/gorelease.yml:42","Info:   0 out of  16 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   6 third-party GitHubAction dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2025-3372 / GHSA-6wxm-mpqj-6jpf","Warn: Project is vulnerable to: GO-2024-2687 / GHSA-4v7x-pqxf-cx7m","Warn: Project is vulnerable to: GO-2024-3333","Warn: Project is vulnerable to: GO-2025-3503 / GHSA-qxp5-gwg8-xv66","Warn: Project is vulnerable to: GO-2025-3595 / GHSA-vvgc-356p-c3xw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 26 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T07:55:54.037Z","repository_id":37797802,"created_at":"2025-08-17T07:55:54.038Z","updated_at":"2025-08-17T07:55:54.038Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28883091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T19:23:39.025Z","status":"ssl_error","status_checked_at":"2026-01-29T19:22:11.631Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","cache-stampede","cachemanager","go","resiliency"],"created_at":"2026-01-29T19:33:32.410Z","updated_at":"2026-01-29T19:33:32.466Z","avatar_url":"https://github.com/bool64.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# High performance resilient in-memory cache for Go\n\nThis library defines cache interfaces and provides in-memory implementations.\n\n[![Build Status](https://github.com/bool64/cache/workflows/test-unit/badge.svg)](https://github.com/bool64/cache/actions?query=branch%3Amaster+workflow%3Atest-unit)\n[![Coverage Status](https://codecov.io/gh/bool64/cache/branch/master/graph/badge.svg)](https://codecov.io/gh/bool64/cache)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/bool64/cache)\n[![time tracker](https://wakatime.com/badge/github/bool64/cache.svg)](https://wakatime.com/badge/github/bool64/cache)\n![Code lines](https://sloc.xyz/github/bool64/cache/?category=code)\n![Comments](https://sloc.xyz/github/bool64/cache/?category=comments)\n\n## Why?\n\nThere are a few libraries that provide in-memory cache already, why another one?\n\nThis library addresses additional practical issues that are not usually covered by key-value storage concerns. It helps\nto improve performance and resiliency by gentle handling of cache misses and allows for comprehensive observability with \nfine control of caching behavior.\n\nPlease check this [blog post](https://dev.to/vearutop/implementing-robust-in-memory-cache-with-go-196e) for more details.\n\n## Failover Cache\n\n[`Failover`](https://pkg.go.dev/github.com/bool64/cache#Failover) is a cache frontend to manage cache updates in a\nnon-conflicting and performant way.\n\nAn instance can be created with [`NewFailover`](https://pkg.go.dev/github.com/bool64/cache#NewFailover) and functional\noptions.\n\nMain API is a `Get` function that takes a key and a builder function. If value is available in cache, it is served from\ncache and builder function is not invoked. If value is not available in cache, builder function is invoked and the\nresult is stored in cache.\n\n```go\n// Get value from cache or the function.\nv, err := f.Get(ctx, []byte(\"my-key\"), func(ctx context.Context) (interface{}, error) {\n    // Build value or return error on failure.\n\n    return \"\u003cvalue\u003e\", nil\n})\n```\n\nOr, starting with go1.18 you can use generic API.\n\n```go\nf := cache.NewFailoverOf[Dog](func(cfg *cache.FailoverConfigOf[Dog]) {\n    // Using last 30 seconds of 5m TTL for background update.\n    cfg.MaxStaleness = 30 * time.Second\n    cfg.BackendConfig.TimeToLive = 5*time.Minute - cfg.MaxStaleness\n})\n\n// Get value from cache or the function.\nv, err := f.Get(ctx, []byte(\"my-key\"), func(ctx context.Context) (Dog, error) {\n    // Build value or return error on failure.\n\n    return Dog{Name: \"Snoopy\"}, nil\n})\n```\n\nAdditionally, there are few other aspects of behavior to optimize performance.\n\n* Builder function is locked per key, so if the key needs a fresh value the builder function is only called once. All\n  the other `Get` calls for the same key are blocked until the value is available. This helps to avoid\n  [cache stampede problem](https://en.wikipedia.org/wiki/Cache_stampede) when popular value is missing or\n  expired.\n* If expired (stale) value is available, the value is refreshed with a short TTL (configured as `UpdateTTL`) before the\n  builder function is invoked. This immediately unblocks readers with a stale value and improves tail latency.\n* If the value has expired longer than `MaxStaleness` ago, stale value is not served and readers are blocked till the\n  builder function return.\n* By default, if stale value is served, it is served to all readers, including the first reader who triggered builder\n  function. Builder function runs in background so that reader latency is not affected. This behavior can be changed\n  with `SyncUpdate` option, so that first reader who invokes builder function is blocked till result is ready instead of\n  having stale value immediately.\n* If builder function fails, the error value is also cached and all consecutive calls for the key, would fail\n  immediately with same error for next 20 seconds (can be configured with `FailedUpdateTTL`). This helps to avoid\n  abusing building function when there is a persistent problem. For example, if you have 100 hits per second for a key\n  that is updated from database and database is temporary down, errors caching prevents unexpected excessive load that\n  usually hides behind value cache.\n* If builder function fails and stale value is available, stale value is served regardless of `MaxStaleness`. This\n  allows to reduce impact of temporary outages in builder function. This behavior can be disabled with `FailHard`\n  option, so that error is served instead of overly stale value.\n\n`Failover` cache uses [`ReadWriter`](https://pkg.go.dev/github.com/bool64/cache#ReadWriter) backend as a storage. By\ndefault [`ShardedMap`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap) is created using `BackendConfig`.\n\nIt is recommended that separate caches are used for different entities, this helps observability on the sizes and\nactivity for particular entities. Cache `Name` can be configured to reflect the purpose. Additionally, `Logger`\nand `Stats` tracker can be provided to collect operating information.\n\nIf `ObserveMutability` is enabled, `Failover` will also emit stats of how often the rebuilt value was different from the\nprevious. This may help to understand data volatility and come up with a better TTL value. The check is done\nwith [`reflect.DeepEqual`](https://pkg.go.dev/reflect#DeepEqual) and may affect performance.\n\n## Sharded Map\n\n[`ShardedMap`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap)\nimplements [`ReadWriter`](https://pkg.go.dev/github.com/bool64/cache#ReadWriter) and few other behaviours with in-memory\nstorage sharded by key. It offers good performance for concurrent usage. Values can expire.\n\nAn instance can be created with [`NewShardedMap`](https://pkg.go.dev/github.com/bool64/cache#NewShardedMap) and\nfunctional options.\n\nGeneric API is also available with [`NewShardedMapOf`](https://pkg.go.dev/github.com/bool64/cache#NewShardedMapOf).\n\nIt is recommended that separate caches are used for different entities, this helps observability on the sizes and\nactivity for particular entities. Cache `Name` can be configured to reflect the purpose. Additionally, `Logger`\nand `Stats` tracker can be provided to collect operating information.\n\nExpiration is configurable with `TimeToLive` and defaults to 5 minutes. It can be changed to a particular key via\ncontext by [`cache.WithTTL`](https://pkg.go.dev/github.com/bool64/cache#WithTTL).\n\nActual TTL applied to a particular key is randomly altered in ±5% boundaries (configurable with `ExpirationJitter`),\nthis helps against synchronous cache expiration (and excessive load to refresh many values at the same time) in case\nwhen many cache entries were created within a small timeframe (for example early after application startup). Expiration\njitter diffuses such synchronization for smoother load distribution.\n\nExpired items are not deleted immediately to reduce the churn rate and to provide stale data for `Failover` cache.\n\nAll items are checked in background once an hour (configurable with `DeleteExpiredJobInterval`) and items that have\nexpired more than 24h ago (configurable with `DeleteExpiredAfter`) are removed.\n\nAdditionally, there are `HeapInUseSoftLimit` and `CountSoftLimit` to trigger eviction of 10% (configurable\nwith `EvictFraction`) entries if count of items or application heap in use exceeds the limit. Limit check and\noptional eviction are triggered right after expired items check (in the same background job).\n\n`EvictionStrategy` defines which entries would be evicted, by default `EvictMostExpired` is used.\nIt selects entries with the longest expiration overdue or those that are soonest to expire.\n\nAlternatively `EvictLeastRecentlyUsed` (LRU) and `EvictLeastFrequentlyUsed` (LFU) can be used at cost \nof minor performance impact (for updating counters on each cache serve).\n\nKeep in mind that eviction happens in response to soft limits that are checked periodically, so\ndataset may stay above eviction threshold, especially if `EvictFraction` combined with `DeleteExpiredJobInterval` \nare lower than speed of growth.\n\n### Batch Operations\n\n[`ShardedMap`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap)\nhas [`ExpireAll`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.ExpireAll) function to mark all entries as\nexpired, so that they are updated on next read and are available as stale values in meantime, this function does not\naffect memory usage.\n\nIn contrast, [`DeleteAll`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.DeleteAll) removes all entries and\nfrees the memory, stale values are not available after this operation.\n\nDeleting or expiring all items in multiple caches can be done with help\nof [`cache.Invalidator`](https://pkg.go.dev/github.com/bool64/cache#Invalidator). Deletion/expiration function can be\nappended to `Invalidator.Callbacks` and it will be triggered\non [`Invalidator.Invalidate`](https://pkg.go.dev/github.com/bool64/cache#Invalidator.Invalidate). This may be useful as\na debugging/firefighting tool.\n\nDeleting of multiple related (labeled) items can be done with \n[`InvalidationIndex`](https://pkg.go.dev/github.com/bool64/cache#InvalidationIndex).\n\n[`Len`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.Len) returns currently available number of entries (\nincluding expired).\n\n[`Walk`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.Walk) iterates all entries and invokes a callback for\neach entry, iteration stops if callback fails.\n\nCached entries can be dumped as a binary stream\nwith [`Dump`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.Dump) and restored from a binary stream\nwith [`Restore`](https://pkg.go.dev/github.com/bool64/cache#ShardedMap.Restore), this may enable cache transfer between\nthe instances of an application to avoid cold state after startup. Binary serialization is done\nwith [`encoding/gob`](https://pkg.go.dev/encoding/gob), cached types that are to be dumped/restored have to be\nregistered with [`cache.GobRegister`](https://pkg.go.dev/github.com/bool64/cache#GobRegister).\n\nDumping and walking cache are non-blocking operations and are safe to use together with regular reads/writes,\nperformance impact is expected to be negligible.\n\n[`HTTPTransfer`](https://pkg.go.dev/github.com/bool64/cache#HTTPTransfer) is a helper to transfer caches over HTTP.\nHaving multiple cache instances registered, it\nprovides [`Export`](https://pkg.go.dev/github.com/bool64/cache#HTTPTransfer.Export) HTTP handler that can be plugged\ninto the HTTP server and serve data for an [`Import`](https://pkg.go.dev/github.com/bool64/cache#HTTPTransfer.Import)\nfunction of another application instance.\n\n[`HTTPTransfer.Import`](https://pkg.go.dev/github.com/bool64/cache#HTTPTransfer.Import) fails if cached types differ\nfrom the exporting application instance, for example because of different versions of applications. The check is based\non [`cache.GobTypesHash`](https://pkg.go.dev/github.com/bool64/cache#GobTypesHash)\nthat is calculated from cached structures\nduring [`cache.GobRegister`](https://pkg.go.dev/github.com/bool64/cache#GobRegister).\n\n## Sync Map\n\n[`SyncMap`](https://pkg.go.dev/github.com/bool64/cache#SyncMap)\nimplements [`ReadWriter`](https://pkg.go.dev/github.com/bool64/cache#ReadWriter) and few other behaviours with in-memory\nstorage backed by standard [`sync.Map`](https://pkg.go.dev/sync#Map). It implements same behaviors\nas [`ShardedMap`](#sharded-map) and can be a replacement. There is slight performance difference in latency and\nusually `ShardedMap` tends to consume less memory.\n\n## Context\n\nContext is propagated from parent goroutine to `Failover` and further to backend `ReadWriter` and builder function. In\naddition to usual responsibilities (cancellation, tracing, etc...), context can carry cache options.\n\n* [`cache.WithTTL`](https://pkg.go.dev/github.com/bool64/cache#WithTTL)\n  and [`cache.TTL`](https://pkg.go.dev/github.com/bool64/cache#TTL) to set and get time to live for a particular\n  operation.\n* [`cache.WithSkipRead`](https://pkg.go.dev/github.com/bool64/cache#WithSkipRead)\n  and [`cache.SkipRead`](https://pkg.go.dev/github.com/bool64/cache#SkipRead) to set and get skip reading flag, if the\n  flag is set `Read` function should return `ErrNotFound`, therefore bypassing cache. At the same time `Write` operation\n  is not affected by this flag, so `SkipRead` can be used to force cache refresh.\n\nA handy use case for [`cache.WithSkipRead`](https://pkg.go.dev/github.com/bool64/cache#WithSkipRead) could be to\nimplement a debug mode for request processing with no cache. Such debug mode can be implemented with HTTP (or other\ntransport) middleware that instruments context under certain conditions, for example if a special header is found in\nrequest.\n\n### Detached Context\n\nWhen builder function is invoked in background, the context is detached into a new one, derived context is not\ncancelled/failed/closed if parent context is.\n\nFor example, original context was created for an incoming HTTP request and was closed once response was written,\nmeanwhile the cache update that was triggered in this context is still being processed in background. If original\ncontext was used, background processing would have been cancelled once parent HTTP request is fulfilled, leading to\nupdate failure.\n\nDetached context makes background job continue even after the original context was legitimately closed.  \n\n## Performance\n\n`Failover` cache adds some overhead, but overall performance is still good (especially for IO-bound applications).\n\nPlease check detailed [benchmarks](./_benchmark/README.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbool64%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbool64%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbool64%2Fcache/lists"}