{"id":17116476,"url":"https://github.com/dakimura/readthrough","last_synced_at":"2025-06-28T17:07:44.156Z","repository":{"id":137757621,"uuid":"211653565","full_name":"dakimura/readthrough","owner":"dakimura","description":"Read-through cache implemented in Go","archived":false,"fork":false,"pushed_at":"2019-09-30T10:03:30.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-11T04:03:30.296Z","etag":null,"topics":["cache","go","inmemory-cache","proxy","readthrough","storage"],"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/dakimura.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":"2019-09-29T11:37:58.000Z","updated_at":"2024-06-19T08:03:01.483Z","dependencies_parsed_at":"2024-06-19T08:03:01.262Z","dependency_job_id":"b665a505-be8d-464c-927d-12dd580750de","html_url":"https://github.com/dakimura/readthrough","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/dakimura/readthrough","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakimura%2Freadthrough","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakimura%2Freadthrough/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakimura%2Freadthrough/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakimura%2Freadthrough/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dakimura","download_url":"https://codeload.github.com/dakimura/readthrough/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakimura%2Freadthrough/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262465751,"owners_count":23315640,"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":["cache","go","inmemory-cache","proxy","readthrough","storage"],"created_at":"2024-10-14T17:48:56.790Z","updated_at":"2025-06-28T17:07:44.136Z","avatar_url":"https://github.com/dakimura.png","language":"Go","readme":"# readthrough\n\n## Overview\nThis library is to implement read-through cache quickly in your application.\n\n\nIn order to improve the application performance, we sometimes implement caching.\nBut it takes time because we need to implement a cache accessor,\nintegrate it to your business logic, unit tests and integration tests of it.\nThis library is to get a quick win to improve your application performance without changing your application code much, by a simple read-through cache.\n\nAlso you can implement your own caching (e.g. redis or memcache) to customize this library.\n\n## Installation\n```go\nimport \"github.com/dakimura/readthrough\"\n```\n\n## Usage\nThe usage of this library is to just wrap a slow function that you want to improve performance\nlike as follows:\n```go\nrt := readthrough.Through{Proxy: readthrough.NewInMemoryProxy()}\n\nvalue, _ := rt.Get(\"cacheKey\", someSlowFunction)\n```\n\nWhen `someSlowFunction` is called with the `cacheKey`, the returned values are cached with `cacheKey`. So the cached value will be returned immediately when the function is called again.\n\nNote: We assume that your application has a slow function which returns `(interface{}, error)` .\n```go\nfunc someSlowFunction() (interface{}, error) {\n\t// example\n\ttime.Sleep(3 * time.Second)\n\treturn \"hoge\", nil\n}\n```\nIf the returned values are not `(interface{}, error)` \nplease wrap the function and make another function which returns `(interface{}, error)` .\n\n## Example Code\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/dakimura/readthrough\"\n\t\"time\"\n)\n\nvar rt = readthrough.Through{Proxy: readthrough.NewInMemoryProxy()}\n\nfunc main() {\n\tfmt.Println(\"before try... current time: \" + time.Now().String())\n\n\tcacheKey := \"hello\"\n\t// 1st try takes 3 seconds\n\tvalue, _ := rt.Get(cacheKey, someSlowFunction)\n\tfmt.Println(value.(string))\n\n\t// 2nd try takes almost 0 second\n\tvalue, _ = rt.Get(cacheKey, someSlowFunction)\n\tfmt.Println(value.(string))\n}\n\nfunc someSlowFunction() (interface{}, error) {\n\ttime.Sleep(3 * time.Second)\n\treturn \"current time: \" + time.Now().String(), nil\n}\n```\n\nOutput:\n```go\nbefore try... current time: 2019-09-30 19:02:02.941276 +0900 JST m=+0.000198594\ncurrent time: 2019-09-30 19:02:05.943923 +0900 JST m=+3.002818374\ncurrent time: 2019-09-30 19:02:05.943923 +0900 JST m=+3.002818374\n```\n\n## Original Proxy\nIn the examples above, `proxy.NewInMemoryProxy()` is used for the proxy storage.\nIf you want to use another storage for the cache, please implement your own `proxy.Proxy` implementation.\n\nproxy/proxy.go\n```go\n// Proxy behaves as a read-through cache for an origin (DB, API server, etc)\ntype Proxy interface {\n\tGet(key string) (bool, interface{}, error)\n\tSet(key string, val interface{}) error\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakimura%2Freadthrough","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdakimura%2Freadthrough","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakimura%2Freadthrough/lists"}