{"id":27203232,"url":"https://github.com/go-universal/cache","last_synced_at":"2026-04-30T15:31:14.948Z","repository":{"id":286774508,"uuid":"962431078","full_name":"go-universal/cache","owner":"go-universal","description":"Advanced Redis and in-memory caching for Go.","archived":false,"fork":false,"pushed_at":"2025-08-09T10:35:16.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T12:23:25.546Z","etag":null,"topics":["caching","golang","queue","rate-limiting","redis-cache","verification-code"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-universal.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":"2025-04-08T06:36:16.000Z","updated_at":"2025-08-09T10:35:11.000Z","dependencies_parsed_at":"2025-04-08T10:22:26.874Z","dependency_job_id":"64c92f47-1e1c-4229-988b-43c1b32fa62b","html_url":"https://github.com/go-universal/cache","commit_stats":null,"previous_names":["go-universal/cache"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/go-universal/cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-universal","download_url":"https://codeload.github.com/go-universal/cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Fcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32469344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"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":["caching","golang","queue","rate-limiting","redis-cache","verification-code"],"created_at":"2025-04-09T22:29:11.931Z","updated_at":"2026-04-30T15:31:14.933Z","avatar_url":"https://github.com/go-universal.png","language":"Go","readme":"# Cache Library Documentation\n\n![GitHub Tag](https://img.shields.io/github/v/tag/go-universal/cache?sort=semver\u0026label=version)\n[![Go Reference](https://pkg.go.dev/badge/github.com/go-universal/cache.svg)](https://pkg.go.dev/github.com/go-universal/cache)\n[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/go-universal/cache/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/go-universal/cache)](https://goreportcard.com/report/github.com/go-universal/cache)\n![Contributors](https://img.shields.io/github/contributors/go-universal/cache)\n![Issues](https://img.shields.io/github/issues/go-universal/cache)\n\nThis library provides a flexible and extensible caching system with support for in-memory and Redis-based caching. It includes utilities for managing rate limiters, queues, and verification codes.\n\n## Cache\n\nThe `Cache` interface provides a unified API for caching operations:\n\n- `Put(key string, value any, ttl *time.Duration) error`: Store a value with an optional TTL.\n- `Update(key string, value any) (bool, error)`: Update an existing key.\n- `PutOrUpdate(key string, value any, ttl *time.Duration) error`: Store or update a value.\n- `Get(key string) (any, error)`: Retrieve a value.\n- `Pull(key string) (any, error)`: Retrieve and remove a value.\n- `Cast(key string) (cast.Caster, error)`: Retrieve and cast a value.\n- `Exists(key string) (bool, error)`: Check if a key exists.\n- `Forget(key string) error`: Remove a key.\n- `TTL(key string) (time.Duration, error)`: Get the TTL of a key.\n- `Increment(key string, value int64) (bool, error)`: Increment a numeric value.\n- `Decrement(key string, value int64) (bool, error)`: Decrement a numeric value.\n- `IncrementFloat(key string, value float64) (bool, error)`: Increment a float value.\n- `DecrementFloat(key string, value float64) (bool, error)`: Decrement a float value.\n\n## Memory Cache\n\nThe `MemoryCache` is an in-memory implementation of the `Cache` interface:\n\n```go\ncache := cache.NewMemoryCache()\nttl := 5 * time.Second\nerr := cache.Put(\"key\", \"value\", \u0026ttl)\nvalue, err := cache.Get(\"key\")\n```\n\n## Redis Cache\n\nThe `RedisCache` is a Redis-based implementation of the `Cache` interface:\n\n```go\nredisClient := redis.NewClient(\u0026redis.Options{})\ncache := cache.NewRedisCache(\"prefix\", redisClient)\nttl := 5 * time.Second\nerr := cache.Put(\"key\", \"value\", \u0026ttl)\nvalue, err := cache.Get(\"key\")\n```\n\n## Queue\n\nThe `Queue` provides methods for managing a queue:\n\n- `Push(value any) error`: Add a value.\n- `Pull() (any, error)`: Retrieve and remove the first item.\n- `Pop() (any, error)`: Retrieve and remove the last item.\n- `Cast() (cast.Caster, error)`: Retrieve and cast the first item.\n- `Length() (int64, error)`: Get the number of items.\n- `Clear() error`: Remove all items.\n\n## Rate Limiter\n\nThe `RateLimiter` manages rate limits:\n\n- `Hit() error`: Decrement remaining attempts.\n- `Lock() error`: Lock the rate limiter.\n- `Reset() error`: Reset the rate limiter.\n- `Clear() error`: Remove the rate limiter.\n- `MustLock() (bool, error)`: Check if locking is required.\n- `TotalAttempts() (uint32, error)`: Get total attempts.\n- `RetriesLeft() (uint32, error)`: Get remaining attempts.\n- `AvailableIn() (time.Duration, error)`: Time until unlock.\n\n## Verification Code\n\nThe `VerificationCode` manages verification codes:\n\n- `Set(code string) error`: Store a code.\n- `Generate(count uint) (string, error)`: Generate a random code.\n- `Clear() error`: Clear the code.\n- `Get() (string, error)`: Retrieve the code.\n- `Validate(code string) (bool, error)`: Validate a code.\n- `Exists() (bool, error)`: Check if a code exists.\n- `TTL() (time.Duration, error)`: Get the TTL of the code.\n\n## License\n\nThis project is licensed under the ISC License. See the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-universal%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Fcache/lists"}