{"id":36455302,"url":"https://github.com/baekhyunee7/recache","last_synced_at":"2026-01-11T23:02:37.565Z","repository":{"id":248647995,"uuid":"818178767","full_name":"baekhyunee7/recache","owner":"baekhyunee7","description":"redis cache for database","archived":false,"fork":false,"pushed_at":"2024-07-16T06:48:44.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-17T09:16:28.938Z","etag":null,"topics":["database","go-redis","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baekhyunee7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-06-21T09:11:39.000Z","updated_at":"2024-07-16T06:47:42.000Z","dependencies_parsed_at":"2024-07-16T09:06:36.984Z","dependency_job_id":"a4653672-e844-4768-a323-d6678bea8a3c","html_url":"https://github.com/baekhyunee7/recache","commit_stats":null,"previous_names":["baekhyunee7/recache"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/baekhyunee7/recache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baekhyunee7%2Frecache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baekhyunee7%2Frecache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baekhyunee7%2Frecache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baekhyunee7%2Frecache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baekhyunee7","download_url":"https://codeload.github.com/baekhyunee7/recache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baekhyunee7%2Frecache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28326166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T22:11:01.104Z","status":"ssl_error","status_checked_at":"2026-01-11T22:10:58.990Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["database","go-redis","redis"],"created_at":"2026-01-11T23:02:37.504Z","updated_at":"2026-01-11T23:02:37.555Z","avatar_url":"https://github.com/baekhyunee7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# recache\nredis cache for database\n\n# example\n```go\ntype s struct {\n\tID int64  `json:\"id\" gorm:\"primaryKey\"`\n\tA  int    `json:\"a\"`\n\tB  string `json:\"b\"`\n}\n\nfunc main() {\n\tdb, _ := gorm.Open(sqlite.Open(\"file::memory:?cache=shared\"), \u0026gorm.Config{})\n\tdb.AutoMigrate(\u0026s{})\n\tredisServer, _ := miniredis.Run()\n\tred := redis.NewClient(\u0026redis.Options{\n\t\tAddr: redisServer.Addr(),\n\t})\n\tcache := recache.NewCache(red, recache.WithStatInterval(time.Second))\n\tcache.Exec(context.Background(), func() error {\n\t\treturn db.Create(\u0026s{\n\t\t\tID: 1,\n\t\t\tA:  100,\n\t\t\tB:  \"b\",\n\t\t}).Error\n\t}, \"key1\")\n\tget(cache, db, 1)\n\tget(cache, db, 1)\n\tselect {}\n}\n\nfunc get(cache *recache.Cache, db *gorm.DB, id int64) {\n\tvar model s\n\tcache.Query(context.Background(), \"key1\", \u0026model, func(v any) (bool, error) {\n\t\terr := db.Model(\u0026s{}).Where(\"id = ?\", id).First(\u0026v).Error\n\t\tif err != nil {\n\t\t\tif err == gorm.ErrRecordNotFound {\n\t\t\t\treturn false, nil\n\t\t\t}\n\t\t\treturn false, err\n\t\t}\n\t\treturn true, nil\n\t})\n\tfmt.Printf(\"%v\\n\", \u0026model)\n}\n```\n\n* `recache.NewCache` returns a `Cache` instance, optionally privided with options\n* `Cache.Exec` do the write operation and then delete the redis data\n* `Cache.Query` first search for data from redis, if not found, execute the incoming db query parameters. The db query function needs to return whether it is found\n* `Cache.Get` query only from redis\n* `Cache.Set` set only by redis\n* `Cache.Del` delete from redis\n* `Cache.SetWithExpire` set by redis with expiration\n\n### Option\n* `WithLogger` customize logger instance\n* `WithExpire` customize the expiration time of redis data. The expiration time is really less than or equal to this value.\n* `WithHystrixConfig` customize `Hystrix` configration\n* `WithMetricsPort` open `Hystrix` metrics  on configuration port\n* `WithStatInterval` customize stat infomation interval","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaekhyunee7%2Frecache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaekhyunee7%2Frecache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaekhyunee7%2Frecache/lists"}