{"id":18396815,"url":"https://github.com/bartventer/gocache","last_synced_at":"2026-04-29T00:33:19.825Z","repository":{"id":244172869,"uuid":"814113772","full_name":"bartventer/gocache","owner":"bartventer","description":"💾 GoCache is a versatile API for cache management in Go. It supports Redis, Redis Cluster, Memcache, and RAM Cache (in-memory), allowing seamless transitions between them. It simplifies both local testing and different environment deployments.","archived":false,"fork":false,"pushed_at":"2024-10-07T06:20:40.000Z","size":511,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T15:07:58.093Z","etag":null,"topics":["cache","go","golang","in-memory","memcache","portable","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bartventer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-06-12T11:15:37.000Z","updated_at":"2024-07-26T13:30:13.000Z","dependencies_parsed_at":"2024-12-24T10:32:09.523Z","dependency_job_id":"884bcf03-bbdd-44b2-96e9-cb9cffc42def","html_url":"https://github.com/bartventer/gocache","commit_stats":null,"previous_names":["bartventer/gocache"],"tags_count":188,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fgocache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fgocache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fgocache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartventer%2Fgocache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartventer","download_url":"https://codeload.github.com/bartventer/gocache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586234,"owners_count":21128997,"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","go","golang","in-memory","memcache","portable","redis"],"created_at":"2024-11-06T02:14:57.422Z","updated_at":"2026-04-29T00:33:14.799Z","avatar_url":"https://github.com/bartventer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cache\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/gocache.svg)](https://pkg.go.dev/github.com/bartventer/gocache)\n[![Release](https://img.shields.io/github/release/bartventer/gocache.svg)](https://github.com/bartventer/gocache/releases/latest)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bartventer/gocache)](https://goreportcard.com/report/github.com/bartventer/gocache)\n[![codecov](https://codecov.io/gh/bartventer/gocache/graph/badge.svg?token=rtp2vxaccX)](https://codecov.io/gh/bartventer/gocache)\n[![Test](https://github.com/bartventer/gocache/actions/workflows/default.yml/badge.svg)](https://github.com/bartventer/gocache/actions/workflows/default.yml)\n![GitHub issues](https://img.shields.io/github/issues/bartventer/gocache)\n[![License](https://img.shields.io/github/license/bartventer/gocache.svg)](LICENSE)\n\nThe `Cache` package in Go provides a unified, portable API for managing caches, enabling developers to write cache-related code once and transition seamlessly between different cache drivers with minimal reconfiguration. This approach simplifies both local testing and deployment to different environments.\n\n## Installation\n\n```bash\ngo get -u github.com/bartventer/gocache\n```\n\n## Supported Cache Implementations\n\n| Name | Author | Docs |\n|------|--------|------|\n| Redis | [go-redis/redis](https://github.com/go-redis/redis) | [![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/gocache/redis.svg)](https://pkg.go.dev/github.com/bartventer/gocache/redis) |\n| Redis Cluster | [go-redis/redis](https://github.com/go-redis/redis) | [![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/gocache/rediscluster.svg)](https://pkg.go.dev/github.com/bartventer/gocache/rediscluster) |\n| Memcache | [bradfitz/gomemcache](https://github.com/bradfitz/gomemcache) | [![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/gocache/memcache.svg)](https://pkg.go.dev/github.com/bartventer/gocache/memcache) |\n| RAM Cache (in-memory) | [bartventer/gocache](https://github.com/bartventer/gocache) | [![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/gocache/ramcache.svg)](https://pkg.go.dev/github.com/bartventer/gocache/ramcache) |\n\n_**Note**: More coming soon!_\n\n_See the [Contributing](#contributing) section if you would like to add a new cache implementation._\n\n## Usage\n\nTo use a cache implementation, import the relevant driver package and use the `OpenCache` function to create a new cache. The cache package will automatically use the correct cache driver based on the URL scheme. Each driver also provides a constructor function for manual initialization.\n\n### Redis\n\nThe [redis](https://pkg.go.dev/github.com/bartventer/gocache/redis) package provides a [Redis](https://redis.io) cache driver using the [go-redis/redis](https://github.com/go-redis/redis) client.\n\n```go\nimport (\n    \"context\"\n    \"log\"\n\n    cache \"github.com/bartventer/gocache\"\n    _ \"github.com/bartventer/gocache/redis\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    urlStr := \"redis://localhost:7000?maxretries=5\u0026minretrybackoff=1s\"\n    c, err := cache.OpenCache(ctx, urlStr)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize cache: %v\", err)\n    }\n    // ... use c with the cache.Cache interface\n}\n```\n\n#### Redis Constructor\n\nYou can create a Redis cache with [redis.New](https://pkg.go.dev/github.com/bartventer/gocache/redis#New):\n\n```go\nimport (\n    \"context\"\n\n    \"github.com/bartventer/gocache/redis\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    c := redis.New[string](ctx, \u0026redis.Options{\n        RedisOptions: \u0026redis.RedisOptions{\n            Addr: \"localhost:7000\",\n            MaxRetries: 5,\n            MinRetryBackoff: 1 * time.Second,\n        },\n    })\n    // ... use c with the cache.Cache interface\n}\n```\n\n### Redis Cluster\n\nThe [rediscluster](https://pkg.go.dev/github.com/bartventer/gocache/rediscluster) package provides a [Redis Cluster](https://redis.io/topics/cluster-spec) cache driver using the [go-redis/redis](https://github.com/go-redis/redis) client.\n\n```go\nimport (\n    \"context\"\n    \"log\"\n\n    cache \"github.com/bartventer/gocache\"\n    _ \"github.com/bartventer/gocache/rediscluster\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    urlStr := \"rediscluster://localhost:7000,localhost:7001,localhost:7002?maxretries=5\u0026minretrybackoff=1s\"\n    c, err := cache.OpenCache(ctx, urlStr)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize cache: %v\", err)\n    }\n    // ... use c with the cache.Cache interface\n}\n```\n\n#### Redis Cluster Constructor\n\nYou can create a Redis Cluster cache with [rediscluster.New](https://pkg.go.dev/github.com/bartventer/gocache/rediscluster#New):\n\n```go\nimport (\n    \"context\"\n\n    \"github.com/bartventer/gocache/rediscluster\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    c := rediscluster.New[string](ctx, \u0026rediscluster.Options{\n        ClusterOptions: \u0026rediscluster.ClusterOptions{\n            Addrs: []string{\"localhost:7000\", \"localhost:7001\", \"localhost:7002\"},\n            MaxRetries: 5,\n            MinRetryBackoff: 1 * time.Second,\n        },\n    })\n    // ... use c with the cache.Cache interface\n}\n```\n\n### Memcache\n\nThe [memcache](https://pkg.go.dev/github.com/bartventer/gocache/memcache) package provides a [Memcache](https://memcached.org) cache driver using the [bradfitz/gomemcache](https://github.com/bradfitz/gomemcache) client.\n\n```go\nimport (\n    \"context\"\n    \"log\"\n\n    cache \"github.com/bartventer/gocache\"\n    _ \"github.com/bartventer/gocache/memcache\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    urlStr := \"memcache://localhost:11211\"\n    c, err := cache.OpenCache(ctx, urlStr)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize cache: %v\", err)\n    }\n    // ... use c with the cache.Cache interface\n}\n```\n\n#### Memcache Constructor\n\nYou can create a Memcache cache with [memcache.New](https://pkg.go.dev/github.com/bartventer/gocache/memcache#New):\n\n```go\nimport (\n    \"context\"\n\n    \"github.com/bartventer/gocache/memcache\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    c := memcache.New[string](ctx, \u0026memcache.Options{\n        Addrs: []string{\"localhost:11211\"},\n    })\n    // ... use c with the cache.Cache interface\n}\n```\n\n### RAM Cache (in-memory)\n\nThe [ramcache](https://pkg.go.dev/github.com/bartventer/gocache/ramcache) package provides an in-memory cache driver using a map.\n\n```go\nimport (\n    \"context\"\n    \"log\"\n\n    cache \"github.com/bartventer/gocache\"\n    _ \"github.com/bartventer/gocache/ramcache\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    urlStr := \"ramcache://?cleanupinterval=1m\"\n    c, err := cache.OpenCache(ctx, urlStr)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize cache: %v\", err)\n    }\n    // ... use c with the cache.Cache interface\n}\n```\n\n#### RAM Cache Constructor\n\nYou can create a RAM cache with [ramcache.New](https://pkg.go.dev/github.com/bartventer/gocache/ramcache#New):\n\n```go\nimport (\n    \"context\"\n\n    \"github.com/bartventer/gocache/ramcache\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    c := ramcache.New[string](ctx, \u0026ramcache.Options{\n        CleanupInterval: 1 * time.Minute,\n    })\n    // ... use c with the cache.Cache interface\n}\n```\n\n## Contributing\n\nAll contributions are welcome! See the [Contributing Guide](CONTRIBUTING.md) for more details.\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fgocache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartventer%2Fgocache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartventer%2Fgocache/lists"}