{"id":24583477,"url":"https://github.com/itmisx/go-cache","last_synced_at":"2025-04-28T10:38:22.888Z","repository":{"id":65358463,"uuid":"587537946","full_name":"itmisx/go-cache","owner":"itmisx","description":"类似redis的本地缓存库，支持string和hash。特性：支持hash field过期时间设置以及过期回调","archived":false,"fork":false,"pushed_at":"2023-06-07T15:18:02.000Z","size":50,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T08:41:32.767Z","etag":null,"topics":[],"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/itmisx.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-01-11T01:28:26.000Z","updated_at":"2024-08-28T10:27:03.000Z","dependencies_parsed_at":"2024-06-21T01:45:55.017Z","dependency_job_id":"fd646294-95af-456e-b52d-b1f6f7dca477","html_url":"https://github.com/itmisx/go-cache","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"206f1c2e15e073c5f4d369b70a709966439239e3"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmisx%2Fgo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmisx%2Fgo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmisx%2Fgo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itmisx%2Fgo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itmisx","download_url":"https://codeload.github.com/itmisx/go-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251296530,"owners_count":21566623,"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":"2025-01-24T04:46:42.210Z","updated_at":"2025-04-28T10:38:22.861Z","avatar_url":"https://github.com/itmisx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-cache\n\n一个基于内存的 key/value 的 go 语言存储库，支持 string 和 hash, 类似redis\n\n#### 🚀 安装\n\n`go get -u github.com/itmisx/go-cache`\n\n#### ✨ 特性\n\n- 支持过期回调函数\n- 支持哈希字段的过期时间设置\n\n#### 🏗️ 使用场景\n\n主要用在单机或本地缓存场景\n\n#### ✅ 开始使用\n\n- 设置键值，不带过期回调\n\n```go\ncache.Set(\"key1\", 1, time.Second*4, nil)\n```\n\n- 设置键值，带过期回调\n\n```go\ncache.Set(\"key1\", 1, time.Second*4, func(key string, value interface{}) {\n    log.Println(\"callback1\", key, value)\n})\n```\n\n- 设置键的过期时间\n\n```go\ncache.Expire(\"key1\",time.Second*4)\n```\n\n- 获取键值\n\n```go\n// found指示是否存在\nvalue,found := cache.Get(\"key1\")\n```\n\n- 删除键\n\n```go\ncache.Del(\"key1\")\n```\n\n- 设置 hash，带过期回调\n\n```go\ncache.HSet(\"hkey1\", \"hfield1\", 1, time.Second*8, func(key string, field string, value interface{}) {\n    log.Println(\"callback2\", key, field, value)\n})\n```\n\n- 设置 hash 字段的过期时间\n\n```go\ncache.Expire(\"hkey1\",\"hfield1\",time.Second*3)\n```\n\n- 获取 hash 值\n\n```go\n// found指示是否存在\nvalue,found := cache.HGet(\"hkey1\",\"hfield1\")\n```\n\n- 获取所有的hash值\n\n```go\nval,found:=cache.HGetAll(\"hkey1\")\n```\n\n- 删除 hash 字段\n\n```go\nval,fount:=cache.HDel(\"hkey1\",\"hfield1\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitmisx%2Fgo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitmisx%2Fgo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitmisx%2Fgo-cache/lists"}