{"id":20724673,"url":"https://github.com/arhea/go-cacher","last_synced_at":"2025-07-08T09:41:48.594Z","repository":{"id":210428461,"uuid":"726534818","full_name":"arhea/go-cacher","owner":"arhea","description":"Provides an easy to use interface on top of the official Go Redis client. Includes a Generics based client.","archived":false,"fork":false,"pushed_at":"2024-03-06T13:58:34.000Z","size":78,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-15T01:56:54.879Z","etag":null,"topics":["go","golang","golang-library","golang-package","redis","redis-client"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/arhea/go-cacher","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/arhea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["arhea"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-12-02T17:01:22.000Z","updated_at":"2023-12-08T15:19:25.000Z","dependencies_parsed_at":"2024-03-06T14:58:45.703Z","dependency_job_id":null,"html_url":"https://github.com/arhea/go-cacher","commit_stats":null,"previous_names":["arhea/go-cacher"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fgo-cacher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fgo-cacher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fgo-cacher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arhea%2Fgo-cacher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arhea","download_url":"https://codeload.github.com/arhea/go-cacher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224996464,"owners_count":17404487,"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":["go","golang","golang-library","golang-package","redis","redis-client"],"created_at":"2024-11-17T04:15:57.193Z","updated_at":"2024-11-17T04:15:57.615Z","avatar_url":"https://github.com/arhea.png","language":"Go","funding_links":["https://github.com/sponsors/arhea"],"categories":[],"sub_categories":[],"readme":"# Cacher\n\n![Tests](https://github.com/arhea/go-cacher/actions/workflows/main.yml/badge.svg?branch=main) ![goreportcard](https://goreportcard.com/badge/github.com/arhea/go-cacher) ![GitHub License](https://img.shields.io/github/license/arhea/go-mock-spanner) [![Go Reference](https://pkg.go.dev/badge/github.com/arhea/go-cacher.svg)](https://pkg.go.dev/github.com/arhea/go-cacher)\n\nInspired by the [Laravel Cache Facade](https://laravel.com/docs/10.x/cache), `cacher` provides a convenient wrapper around the official [Redis client](https://github.com/redis/go-redis). This library provides two methods for interacting with Redis. The first is via standard types such as strings, bytes, numbers, etc. However, often times we want to store structs. Cacher also ships with an Entity cache that uses generics. This client automatically marshalls the structs using JSON to and from the redis cache.\n\n## Usage\n\n### Client\n\nThe client provides a standard wrapper around the Redis client.\n\n```golang\n\nrdb := redis.NewClient(\u0026redis.Options{\n    Addr:     \"localhost:6379\",\n    Password: \"\", // no password set\n    DB:       0,  // use default DB\n})\n\ncache := cacher.New(rdb)\n\n// fetch a value from the cache or from our database if it doesnt existing the cache\nvalue, err := cache.RememberString(ctx, \"my-key\", time.Hour*24, func(ctx context.Context) (string, error) {\n    // ... fetch value from database\n\n    return databaseValue, nil\n})\n\n// put a value in the cache\nerr := cache.Put(ctx, \"my-key\", \"hello-world\", time.Hour*24)\n\nerr := cache.PutForever(ctx, \"my-key\", \"hello-world\")\n\n// get a string from the cache\nvalue, err := cache.GetString(ctx, \"my-key\")\n\n// delete a key in the database\nerr := cache.Forget(ctx, \"my-key\")\n\n```\n\n### Entity Client\n\nThe entity client uses generics and JSON marshalling for automatically marhsalling data to and from the cache.\n\n```golang\ntype MyEntity struct {}\n\nrdb := redis.NewClient(\u0026redis.Options{\n    Addr:     \"localhost:6379\",\n    Password: \"\", // no password set\n    DB:       0,  // use default DB\n})\n\ncache := cacher.NewEntity[MyEntity](rdb)\n\n// fetch a value from the cache or from our database if it doesnt existing the cache\nvalue, err := cache.Remember(ctx, \"my-key\", time.Hour*24, func(ctx context.Context) (*MyEntity, error) {\n    // ... fetch value from database\n    return databaseValue, nil\n})\n\n// put a value in the cache\nerr := cache.Put(ctx, \"my-key\", \u0026MyEntity{}, time.Hour*24)\n\nerr := cache.PutForever(ctx, \"my-key\", \u0026MyEntity{})\n\n// get a string from the cache\nvalue, err := cache.Get(ctx, \"my-key\")\n\n// delete a key in the database\nerr := cache.Forget(ctx, \"my-key\")\n```\n\n## Sponsors\n\n`Cacher` is a non-commercial open source project. If you want to support `Cacher`, you can sponsor the project through Github.\n\n## License\n\nCopyright © 2023 Alex Rhea. This project is available with the [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farhea%2Fgo-cacher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farhea%2Fgo-cacher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farhea%2Fgo-cacher/lists"}