{"id":13397082,"url":"https://github.com/muesli/cache2go","last_synced_at":"2025-05-14T10:14:30.713Z","repository":{"id":11757936,"uuid":"14290813","full_name":"muesli/cache2go","owner":"muesli","description":"Concurrency-safe Go caching library with expiration capabilities and access counters","archived":false,"fork":false,"pushed_at":"2024-07-02T15:31:52.000Z","size":119,"stargazers_count":2144,"open_issues_count":34,"forks_count":512,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-04-02T02:09:19.282Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"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/muesli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"github":"muesli"}},"created_at":"2013-11-11T03:45:02.000Z","updated_at":"2025-03-31T11:29:06.000Z","dependencies_parsed_at":"2024-06-18T11:12:02.985Z","dependency_job_id":"8d2571e0-cb0f-48f1-8944-f8014e16f39c","html_url":"https://github.com/muesli/cache2go","commit_stats":{"total_commits":182,"total_committers":14,"mean_commits":13.0,"dds":"0.17582417582417587","last_synced_commit":"518229cd8021d8568e4c6c13743bb050dc1f3a05"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fcache2go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fcache2go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fcache2go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fcache2go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muesli","download_url":"https://codeload.github.com/muesli/cache2go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247968368,"owners_count":21025823,"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":["hacktoberfest"],"created_at":"2024-07-30T18:01:10.659Z","updated_at":"2025-04-09T03:09:52.450Z","avatar_url":"https://github.com/muesli.png","language":"Go","readme":"# cache2go\n\n[![Latest Release](https://img.shields.io/github/release/muesli/cache2go.svg)](https://github.com/muesli/cache2go/releases)\n[![Build Status](https://github.com/muesli/cache2go/workflows/build/badge.svg)](https://github.com/muesli/cache2go/actions)\n[![Coverage Status](https://coveralls.io/repos/github/muesli/cache2go/badge.svg?branch=master)](https://coveralls.io/github/muesli/cache2go?branch=master)\n[![Go ReportCard](https://goreportcard.com/badge/muesli/cache2go)](https://goreportcard.com/report/muesli/cache2go)\n[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://pkg.go.dev/github.com/muesli/cache2go)\n\nConcurrency-safe golang caching library with expiration capabilities.\n\n## Installation\n\nMake sure you have a working Go environment (Go 1.2 or higher is required).\nSee the [install instructions](https://golang.org/doc/install.html).\n\nTo install cache2go, simply run:\n\n    go get github.com/muesli/cache2go\n\nTo compile it from source:\n\n    cd $GOPATH/src/github.com/muesli/cache2go\n    go get -u -v\n    go build \u0026\u0026 go test -v\n\n## Example\n```go\npackage main\n\nimport (\n\t\"github.com/muesli/cache2go\"\n\t\"fmt\"\n\t\"time\"\n)\n\n// Keys \u0026 values in cache2go can be of arbitrary types, e.g. a struct.\ntype myStruct struct {\n\ttext     string\n\tmoreData []byte\n}\n\nfunc main() {\n\t// Accessing a new cache table for the first time will create it.\n\tcache := cache2go.Cache(\"myCache\")\n\n\t// We will put a new item in the cache. It will expire after\n\t// not being accessed via Value(key) for more than 5 seconds.\n\tval := myStruct{\"This is a test!\", []byte{}}\n\tcache.Add(\"someKey\", 5*time.Second, \u0026val)\n\n\t// Let's retrieve the item from the cache.\n\tres, err := cache.Value(\"someKey\")\n\tif err == nil {\n\t\tfmt.Println(\"Found value in cache:\", res.Data().(*myStruct).text)\n\t} else {\n\t\tfmt.Println(\"Error retrieving value from cache:\", err)\n\t}\n\n\t// Wait for the item to expire in cache.\n\ttime.Sleep(6 * time.Second)\n\tres, err = cache.Value(\"someKey\")\n\tif err != nil {\n\t\tfmt.Println(\"Item is not cached (anymore).\")\n\t}\n\n\t// Add another item that never expires.\n\tcache.Add(\"someKey\", 0, \u0026val)\n\n\t// cache2go supports a few handy callbacks and loading mechanisms.\n\tcache.SetAboutToDeleteItemCallback(func(e *cache2go.CacheItem) {\n\t\tfmt.Println(\"Deleting:\", e.Key(), e.Data().(*myStruct).text, e.CreatedOn())\n\t})\n\n\t// Remove the item from the cache.\n\tcache.Delete(\"someKey\")\n\n\t// And wipe the entire cache table.\n\tcache.Flush()\n}\n```\n\nTo run this example, go to examples/mycachedapp/ and run:\n\n    go run mycachedapp.go\n\nYou can find a [few more examples here](https://github.com/muesli/cache2go/tree/master/examples).\nAlso see our test-cases in cache_test.go for further working examples.\n","funding_links":["https://github.com/sponsors/muesli"],"categories":["Go","Data Integration Frameworks","开源类库","Database","Open source library","数据库","数据库  `go语言实现的数据库`","Generators","Uncategorized","\u003cspan id=\"数据库-database\"\u003e数据库 Database\u003c/span\u003e"],"sub_categories":["Caches","缓存","Advanced Console UIs","Cache","标准 CLI","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuesli%2Fcache2go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuesli%2Fcache2go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuesli%2Fcache2go/lists"}