{"id":20612376,"url":"https://github.com/skynet2/datasource-cache","last_synced_at":"2026-04-21T06:32:28.824Z","repository":{"id":59046481,"uuid":"532815906","full_name":"skynet2/datasource-cache","owner":"skynet2","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-21T20:50:38.000Z","size":76,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-29T14:50:12.022Z","etag":null,"topics":["cache","golang","inmemory","performance","redis"],"latest_commit_sha":null,"homepage":"","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/skynet2.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,"zenodo":null}},"created_at":"2022-09-05T08:45:27.000Z","updated_at":"2025-08-21T20:49:38.000Z","dependencies_parsed_at":"2024-02-17T00:21:51.853Z","dependency_job_id":"d3c77be7-d6e1-4b60-8fd0-ffd259054c57","html_url":"https://github.com/skynet2/datasource-cache","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/skynet2/datasource-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skynet2%2Fdatasource-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skynet2%2Fdatasource-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skynet2%2Fdatasource-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skynet2%2Fdatasource-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skynet2","download_url":"https://codeload.github.com/skynet2/datasource-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skynet2%2Fdatasource-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32080300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T06:27:27.065Z","status":"ssl_error","status_checked_at":"2026-04-21T06:27:21.250Z","response_time":128,"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":["cache","golang","inmemory","performance","redis"],"created_at":"2024-11-16T10:24:12.979Z","updated_at":"2026-04-21T06:32:28.808Z","avatar_url":"https://github.com/skynet2.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Datasource Cache\n\n![build workflow](https://github.com/skynet2/datasource-cache/actions/workflows/build.yaml/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/skynet2/datasource-cache/branch/master/graph/badge.svg?token=5QV4Z8NR6V)](https://codecov.io/gh/skynet2/datasource-cache)\n[![go-report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/skynet2/datasource-cache)](https://pkg.go.dev/github.com/skynet2/datasource-cache?tab=doc)\n\n## Installation\n```shell\ngo get github.com/skynet2/datasource-cache\n```\n\n## Quickstart\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/go-redis/redis/v8\"\n\t\"github.com/rs/zerolog\"\n\tcache \"github.com/skynet2/datasource-cache\"\n\t\"strings\"\n)\n\nfunc main() {\n\tredisClient := redis.NewClient(\u0026redis.Options{\n\t\tAddr: \"localhost:6379\",\n\t})\n\n\tredisCacheProvider := cache.NewRedisCache[TranslatedEntity, string](\n\t\tredisClient)\n\n\tcacheManager := cache.NewCacheBuilder[TranslatedEntity, string](\n\t\tModelVersion, redisCacheProvider).Build()\n\n\ttr := \u0026translateService{cacheManager: cacheManager, dbRepo: \u0026dbRepo{}}\n\n\ttr.GetTranslation(context.TODO(), \"en\", []string{\"web:data1\", \"web:data2\", \"web:data3\"})\n}\n\nconst ModelVersion = uint16(1)\n\ntype dbRepo struct {\n}\n\nfunc (d *dbRepo) GetTokens(ctx context.Context, tokens []string) (map[string]map[string]string, error) {\n\t// retrieve data from db or any other source\n    // for example if we requested 10 tokens, but 8 was in cache, here we`ll have only 2 tokens to request\n\treturn map[string]map[string]string{}, nil\n}\n\ntype TranslationToken struct {\n\tTokenKey     string\n\tTranslations map[string]string\n}\n\ntype TranslatedEntity struct {\n\tValue        string\n\tModelVersion uint16\n}\n\nfunc (t TranslatedEntity) GetCacheModelVersion() uint16 {\n\treturn t.ModelVersion\n}\n\ntype translateService struct {\n\tcacheManager *cache.Cache[TranslatedEntity, string]\n\tdbRepo       *dbRepo\n}\n\nfunc (t *translateService) GetTranslation(\n\tctx context.Context,\n\tlanguage string,\n\tinputTokens []string,\n) (map[string]string, error) {\n\tcacheTokens := make([]*cache.Key[string], 0)\n\n\tfor _, token := range inputTokens {\n\t\ttok := strings.ToLower(token)\n\n\t\tcacheTokens = append(cacheTokens, \u0026cache.Key[string]{\n\t\t\tOriginalValue: tok,                                 // here it will be as web:data1\n\t\t\tKey:           fmt.Sprintf(\"%v:%v\", language, tok), // en:web:data1\n\t\t})\n\t}\n\n\tresult, err := t.cacheManager.MGet(ctx, cacheTokens, func(ctx context.Context, keys []*cache.Key[string]) (map[*cache.Key[string]]*TranslatedEntity, error) {\n\t\ttranslations := make(map[*cache.Key[string]]*TranslatedEntity)\n\t\tmissingTranslations := make(map[string]TranslationToken)\n\n\t\ttoRequest := make([]string, 0, len(keys))\n\t\treverseMap := map[string]*cache.Key[string]{}\n\n\t\tfor _, k := range keys {\n\t\t\ttoRequest = append(toRequest, k.OriginalValue)\n\t\t\treverseMap[k.OriginalValue] = k\n\t\t}\n\n\t\tfoundDbTokens, err := t.dbRepo.GetTokens(ctx, toRequest)\n\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tfor _, key := range toRequest {\n\t\t\tv, ok := reverseMap[key]\n\n\t\t\tif !ok {\n\t\t\t\tzerolog.Ctx(ctx).Warn().Msgf(\"not found in reverse map key %v\", key)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif dbKey, ok := foundDbTokens[key]; ok {\n\t\t\t\ttranslations[v] = \u0026TranslatedEntity{\n\t\t\t\t\tValue:        dbKey[\"default\"], // find proper value\n\t\t\t\t\tModelVersion: ModelVersion,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttranslations[v] = \u0026TranslatedEntity{\n\t\t\t\t\tModelVersion: ModelVersion,\n\t\t\t\t\tValue:        key,\n\t\t\t\t}\n\t\t\t\tmissingTranslations[key] = TranslationToken{\n\t\t\t\t\tTokenKey: key,\n\t\t\t\t\tTranslations: map[string]string{\n\t\t\t\t\t\t\"en\": strings.ToLower(key),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn translations, nil\n\t})\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfinal := make(map[string]string)\n\n\tfor k, v := range result {\n\t\tfinal[k.OriginalValue] = v.Value\n\t}\n\n\treturn final, nil\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskynet2%2Fdatasource-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskynet2%2Fdatasource-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskynet2%2Fdatasource-cache/lists"}