{"id":25623340,"url":"https://github.com/mekramy/gocache","last_synced_at":"2025-08-24T15:18:09.155Z","repository":{"id":277009944,"uuid":"919427239","full_name":"mekramy/gocache","owner":"mekramy","description":"advanced redis/memory cache for go","archived":false,"fork":false,"pushed_at":"2025-02-14T15:47:06.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-22T11:36:26.490Z","etag":null,"topics":["caching","go","golang","mekramy-go","queue","rate-limiter","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/mekramy.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-01-20T11:20:35.000Z","updated_at":"2025-02-14T15:47:03.000Z","dependencies_parsed_at":"2025-02-11T17:37:27.667Z","dependency_job_id":null,"html_url":"https://github.com/mekramy/gocache","commit_stats":null,"previous_names":["mekramy/gocache"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mekramy/gocache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mekramy%2Fgocache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mekramy%2Fgocache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mekramy%2Fgocache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mekramy%2Fgocache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mekramy","download_url":"https://codeload.github.com/mekramy/gocache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mekramy%2Fgocache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271895525,"owners_count":24840095,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","go","golang","mekramy-go","queue","rate-limiter","verification-code"],"created_at":"2025-02-22T11:36:30.584Z","updated_at":"2025-08-24T15:18:08.965Z","avatar_url":"https://github.com/mekramy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoCache Library Documentation\n\n## Overview\n\nThe `gocache` library provides a set of interfaces and implementations for caching, queuing, rate limiting, and verification code generation. It supports both Redis-based and in-memory caching.\n\n## Installation\n\nTo install GoCache, use the following command:\n\n```sh\ngo get github.com/mekramy/gocache\n```\n\n## Cache\n\nKey Features:\n\n- Supports Redis and in-memory caching.\n- Provides functionality to store, retrieve, update, and manage cache keys.\n- Offers type casting for cached values.\n- Includes advanced operations like incrementing, decrementing, and TTL management.\n\nMethods:\n\n- `Put(key string, value any, ttl *time.Duration) error`: Store a value in the cache with a time-to-live (TTL). If nil ttl passed, the value is stored indefinitely.\n- `Set(key string, value any) (bool, error)`: Update the value of an existing key, returns `false` if key not exists.\n- `Override(key string, value any, ttl *time.Duration) error`: Store or update a value in the cache, retaining TTL if the key exists.\n- `Get(key string) (any, error)`: Retrieve a value from the cache.\n- `Pull(key string) (any, error)`: Retrieve and remove a value from the cache.\n- `Cast(key string) (gocast.Caster, error)`: Retrieve and cast a value to a `gocast.Caster`.\n- `Exists(key string) (bool, error)`: Check if a key exists.\n- `Forget(key string) error`: Remove a key from the cache.\n- `TTL(key string) (time.Duration, error)`: Get the time-to-live of a key.\n- `Increment(key string, value int64) (bool, error)`: Increment a key's value by a given integer, returns `false` if key not exists.\n- `Decrement(key string, value int64) (bool, error)`: Decrement a key's value by a given integer, returns `false` if key not exists.\n- `IncrementFloat(key string, value float64) (bool, error)`: Increment a key's value by a given float, returns `false` if key not exists.\n- `DecrementFloat(key string, value float64) (bool, error)`: Decrement a key's value by a given float, returns `false` if key not exists.\n\nCreate a Redis-based cache instance:\n\n```go\nfunc NewRedisCache(prefix string, client *redis.Client) Cache\n```\n\nCreate an in-memory cache instance:\n\n```go\nfunc NewMemoryCache() Cache\n```\n\n## Queue\n\nKey Features:\n\n- Implements a safe, nil-resistant queue interface.\n- Compatible with Redis for distributed queue management.\n- Includes operations to push, pull, and retrieve items with type casting support.\n\nMethods:\n\n- `Push(value any) error`: Add a value to the queue.\n- `Pull() (any, error)`: Retrieve and remove the first item in the queue.\n- `Pop() (any, error)`: Retrieve and remove the last item in the queue.\n- `Cast() (gocast.Caster, error)`: Retrieve and cast the first item in the queue to a `gocast.Caster`.\n- `Length() (int64, error)`: Get the queue length.\n\nCreate a Redis-based queue instance:\n\n```go\nfunc NewRedisQueue(name string, client *redis.Client) Queue\n```\n\n## RateLimiter\n\nKey Features:\n\n- Limit Actions: Tracks and restricts the number of attempts allowed for a specific action, ensuring controlled usage.\n- Locking Support: Automatically locks when the limit is exceeded and provides information about when the lock will be lifted.\n- Easy Reset: Quickly reset the limiter to allow new attempts or clear its state entirely.\n- Retry Tracking: Keeps track of how many retries are left and provides real-time updates.\n\nMethods:\n\n- `Hit() error`: Decrement the remaining attempts.\n- `Lock() error`: Lock the rate limiter.\n- `Reset() error`: Reset the rate limiter.\n- `Clear() error`: Remove the rate limiter from the cache.\n- `MustLock() (bool, error)`: Check if the rate limiter is locked.\n- `TotalAttempts() (uint32, error)`: Get the total number of attempts allowed.\n- `RetriesLeft() (uint32, error)`: Get the remaining attempts.\n- `AvailableIn() (time.Duration, error)`: Get the time until the rate limiter unlocks.\n\nCreate a rate limiter instance:\n\n```go\nfunc NewRateLimiter(name string, maxAttempts uint32, ttl time.Duration, cache Cache) RateLimiter\n```\n\n## VerificationCode\n\nKey Features:\n\n- Handles verification code generation and management.\n- Supports TTL and retry attempt tracking.\n- Allows easy integration with cache for storing verification codes.\n\nMethods:\n\n- `Set(code string) error`: Set a verification code.\n- `Generate(count uint) (string, error)`: Generate a random numeric code of a specified length.\n- `Clear() error`: Remove a verification code from the cache.\n- `Get() (string, error)`: Retrieve a verification code.\n- `Exists() (bool, error)`: Check if a verification code exists.\n- `TTL() (time.Duration, error)`: Get the time-to-live of a verification code.\n\nCreate a verification code instance:\n\n```go\nfunc NewVerification(name string, maxAttempts uint32, ttl time.Duration, cache Cache) VerificationCode\n```\n\n## Dependencies\n\n- `github.com/mekramy/gocast`: Casting library for dynamic type handling.\n- `github.com/redis/go-redis/v9`: Redis client library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmekramy%2Fgocache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmekramy%2Fgocache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmekramy%2Fgocache/lists"}