{"id":13677107,"url":"https://github.com/gookit/cache","last_synced_at":"2025-04-12T21:26:16.743Z","repository":{"id":37550397,"uuid":"147920772","full_name":"gookit/cache","owner":"gookit","description":"🗃  Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more. Go 通用的缓存使用库，通过包装各种常用的驱动，来提供统一的使用API，便于使用。","archived":false,"fork":false,"pushed_at":"2025-04-02T01:54:20.000Z","size":327,"stargazers_count":195,"open_issues_count":3,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T01:06:44.766Z","etag":null,"topics":["buntdb","cache","cache-manager","custom-driver","file-cache","golang","memcached-cache","memory-cache","redis","redis-cache"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/gookit/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/gookit.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":"2018-09-08T09:43:21.000Z","updated_at":"2025-04-02T01:54:18.000Z","dependencies_parsed_at":"2023-10-12T15:32:23.888Z","dependency_job_id":"22ccca8f-e2ff-499a-a626-39953987bbb3","html_url":"https://github.com/gookit/cache","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633451,"owners_count":21136872,"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":["buntdb","cache","cache-manager","custom-driver","file-cache","golang","memcached-cache","memory-cache","redis","redis-cache"],"created_at":"2024-08-02T13:00:37.038Z","updated_at":"2025-04-12T21:26:16.721Z","avatar_url":"https://github.com/gookit.png","language":"Go","funding_links":[],"categories":["Databases"],"sub_categories":[],"readme":"# Cache\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/cache?style=flat-square)\n[![GoDoc](https://godoc.org/github.com/gookit/cache?status.svg)](https://pkg.go.dev/github.com/gookit/cache)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/cache)](https://goreportcard.com/report/github.com/gookit/cache)\n[![Actions Status](https://github.com/gookit/cache/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/cache/actions)\n\n\u003e **[中文说明](README_cn.md)**\n\nGeneric cache use and cache manager for golang. \n\nProvide a unified usage API by packaging various commonly used drivers.\n\n\u003e All cache driver implemented the `cache.Cache` interface. So, You can add any custom driver.\n\n**Packaged Drivers:**\n\n- `goredis` https://github.com/go-redis/redis\n- `redis` https://github.com/gomodule/redigo\n- `memcached` https://github.com/bradfitz/gomemcache\n- `buntdb` https://github.com/tidwall/buntdb\n- `boltdb`  https://github.com/etcd-io/bbolt\n- `badger` https://github.com/dgraph-io/badger\n- `nutsdb` https://github.com/xujiajun/nutsdb\n- `goleveldb` https://github.com/syndtr/goleveldb\n- `gcache` https://github.com/bluele/gcache\n- `gocache` https://github.com/patrickmn/go-cache\n- `bigcache` https://github.com/allegro/bigcache\n\nInternal:\n\n- file internal driver [driver_file.go](driver_file.go)\n- memory internal driver [driver_memory.go](driver_memory.go)\n\n\u003e Notice: The built-in implementation is relatively simple and is not recommended for production environments;\n\u003e the production environment recommends using the third-party drivers listed above.\n\n## GoDoc\n\n- [doc on gowalker](https://gowalker.org/github.com/gookit/cache)\n- [godoc for gopkg](https://pkg.go.dev/gopkg.in/gookit/cache.v1)\n- [godoc for github](https://pkg.go.dev/github.com/gookit/cache)\n\n## Install\n\nThe package supports 3 last Go versions and requires a Go version with modules support.\n\n```bash\ngo get github.com/gookit/cache\n```\n\n## Cache Interface\n\nAll cache driver implemented the `cache.Cache` interface. So, You can add any custom driver.\n\n```go\ntype Cache interface {\n\t// basic operation\n\tHas(key string) bool\n\tGet(key string) any\n\tSet(key string, val any, ttl time.Duration) (err error)\n\tDel(key string) error\n\t// multi operation\n\tGetMulti(keys []string) map[string]any\n\tSetMulti(values map[string]any, ttl time.Duration) (err error)\n\tDelMulti(keys []string) error\n\t// clear and close\n\tClear() error\n\tClose() error\n}\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gookit/cache\"\n\t\"github.com/gookit/cache/gcache\"\n\t\"github.com/gookit/cache/gocache\"\n\t\"github.com/gookit/cache/goredis\"\n\t\"github.com/gookit/cache/redis\"\n)\n\nfunc main() {\n\t// register one(or some) cache driver\n\tcache.Register(cache.DvrFile, cache.NewFileCache(\"\"))\n\t// cache.Register(cache.DvrMemory, cache.NewMemoryCache())\n\tcache.Register(gcache.Name, gcache.New(1000))\n\tcache.Register(gocache.Name, gocache.NewGoCache(cache.OneDay, cache.FiveMinutes))\n\tcache.Register(redis.Name, redis.Connect(\"127.0.0.1:6379\", \"\", 0))\n\tcache.Register(goredis.Name, goredis.Connect(\"127.0.0.1:6379\", \"\", 0))\n\n\t// setting default driver name\n\tcache.DefaultUse(gocache.Name)\n\n\t// quick use.(it is default driver)\n\t//\n\t// set\n\tcache.Set(\"name\", \"cache value\", cache.TwoMinutes)\n\t// get\n\tval := cache.Get(\"name\")\n\t// del\n\tcache.Del(\"name\")\n\n\t// get: \"cache value\"\n\tfmt.Print(val)\n\n\t// More ...\n\t// fc := cache.Driver(gcache.Name)\n\t// fc.Set(\"key\", \"value\", 10)\n\t// fc.Get(\"key\")\n}\n```\n\n## With Options\n\n```go\ngords := goredis.Connect(\"127.0.0.1:6379\", \"\", 0)\ngords.WithOptions(cache.WithPrefix(\"cache_\"), cache.WithEncode(true))\n\ncache.Register(goredis.Name, gords)\n\n// set\n// real key is: \"cache_name\"\ncache.Set(\"name\", \"cache value\", cache.TwoMinutes)\n\n// get: \"cache value\"\nval := cache.Get(\"name\")\n```\n\n## Gookit packages\n\n- [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files\n- [gookit/rux](https://github.com/gookit/rux) Simple and fast request router for golang HTTP\n- [gookit/gcli](https://github.com/gookit/gcli) build CLI application, tool library, running CLI commands\n- [gookit/slog](https://github.com/gookit/slog) Lightweight, extensible, configurable logging library written in Go\n- [gookit/event](https://github.com/gookit/event) Lightweight event manager and dispatcher implements by Go\n- [gookit/cache](https://github.com/gookit/cache) Provide a unified usage API by packaging various commonly used drivers.\n- [gookit/config](https://github.com/gookit/config) Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags\n- [gookit/color](https://github.com/gookit/color) A command-line color library with true color support, universal API methods and Windows support\n- [gookit/filter](https://github.com/gookit/filter) Provide filtering, sanitizing, and conversion of golang data\n- [gookit/validate](https://github.com/gookit/validate) Use for data validation and filtering. support Map, Struct, Form data\n- [gookit/goutil](https://github.com/gookit/goutil) Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more\n- More, please see https://github.com/gookit\n\n## License\n\n**MIT**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fcache/lists"}