{"id":36920330,"url":"https://github.com/devnw/ttl","last_synced_at":"2026-01-12T16:14:42.463Z","repository":{"id":40359906,"uuid":"357862745","full_name":"devnw/ttl","owner":"devnw","description":"TTL (Time To Live) Cache Implementation for Go","archived":false,"fork":false,"pushed_at":"2025-02-27T01:39:49.000Z","size":126,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T21:08:03.904Z","etag":null,"topics":["cache","caching","go","golang","time-to-live","ttl"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devnw.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-14T10:20:26.000Z","updated_at":"2024-12-12T21:10:13.000Z","dependencies_parsed_at":"2024-06-20T21:51:50.654Z","dependency_job_id":"e893dc04-8fe6-4fc3-a862-b755f4c99049","html_url":"https://github.com/devnw/ttl","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":0.180327868852459,"last_synced_commit":"6098c0ea4017cdf8c23c8723e95072450d60709f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"devnw/oss-template","purl":"pkg:github/devnw/ttl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnw%2Fttl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnw%2Fttl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnw%2Fttl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnw%2Fttl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devnw","download_url":"https://codeload.github.com/devnw/ttl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnw%2Fttl/sbom","scorecard":{"id":338006,"data":{"date":"2025-08-11","repo":{"name":"github.com/devnw/ttl","commit":"16630cd965bdf4dda5b53c160d629db2da7eb539"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.2,"checks":[{"name":"Code-Review","score":3,"reason":"Found 3/10 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: jobLevel 'contents' permission set to 'write': .github/workflows/automerge.yml:10","Warn: no topLevel permission defined: .github/workflows/automerge.yml:1","Warn: no topLevel permission defined: .github/workflows/build.yml:1"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/automerge.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/automerge.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/devnw/ttl/build.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v1.1.0 not signed: https://api.github.com/repos/devnw/ttl/releases/62982383","Warn: release artifact dev not signed: https://api.github.com/repos/devnw/ttl/releases/62982449","Warn: release artifact v1.1.0 does not have provenance: https://api.github.com/repos/devnw/ttl/releases/62982383","Warn: release artifact dev does not have provenance: https://api.github.com/repos/devnw/ttl/releases/62982449"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/devnw/.github/SECURITY.md:1","Info: Found linked content: github.com/devnw/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/devnw/.github/SECURITY.md:1","Info: Found text in security policy: github.com/devnw/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2022-1059 / GHSA-69ch-w2m2-3vjp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 23 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T05:11:02.252Z","repository_id":40359906,"created_at":"2025-08-18T05:11:02.252Z","updated_at":"2025-08-18T05:11:02.252Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28342361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T15:50:39.657Z","status":"ssl_error","status_checked_at":"2026-01-12T15:49:49.297Z","response_time":98,"last_error":"SSL_read: 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","caching","go","golang","time-to-live","ttl"],"created_at":"2026-01-12T16:14:41.884Z","updated_at":"2026-01-12T16:14:42.451Z","avatar_url":"https://github.com/devnw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TTL (Time To Live) Cache Implementation for Go\n\n[![Build \u0026 Test Action Status](https://github.com/devnw/ttl/actions/workflows/build.yml/badge.svg)](https://github.com/devnw/ttl/actions)\n[![Go Report Card](https://goreportcard.com/badge/go.devnw.com/ttl)](https://goreportcard.com/report/go.devnw.com/ttl)\n[![codecov](https://codecov.io/gh/devnw/ttl/branch/main/graph/badge.svg)](https://codecov.io/gh/devnw/ttl)\n[![Go Reference](https://pkg.go.dev/badge/go.devnw.com/ttl.svg)](https://go.devnw.com/ttl)\n[![License: Apache 2.0](https://img.shields.io/badge/license-Apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n\n## Overview\n\nA TTL (Time To Live) cache is a data store where data is removed after a defined\nperiod of time to optimize memory performance.\n\n### Implementation\n\n#### TTL Details\n\nThis TTL Cache implementation is designed for ease of use. There are two methods\nfor setting TTL for a data element.\n\n1. TTL is configured when the Cache is instantiated using `ttl.NewCache` which\n   accepts a `time.Duration` parameter for the default TTL of the cache\n   instance. Unless otherwise specified for a specific data element, this is the\n   TTL for all data stored in the cache.\n\n2. TTL for each data element can be configured using the `cache.SetTTL` meethod\n   which accepts a `time.Duration` which will set a specific TTL for that piece\n   of data when it's loaded into the cache.\n\n#### TTL Extension\n\nIn order to optimize data access and retention an `extension` option was\nincluded as part of the implementation of the TTL cache. This can be enabled as\npart of the `NewCache` method. TTL Extension configures the cache so that when\ndata is `READ` from the cache the timeout for that **key/value** pair is reset\nextending the life of that data in memory. This allows for regularly accessed\ndata to be retained while less regularly accessed data is cleared from memory.\n\n## Usage\n\n`go get -u go.devnw.com/ttl@latest`\n\n### Cache Creation\n\nThe `NewCache` method returns an instance of the ttl.Cache[K,V] type to hold\nthe data.\n\n```go\n// NOTE: The KeyType must adhere to the `comparable` constraint\ncache := ttl.NewCache[KeyType, ValueType](\n    // Context used in the application\n    ctx,\n\n    // `time.Duration` that configures the default\n    // timeout for elements of the cache\n    timeout,\n    \n    // boolean which configures whether or not the\n    // timeout should be reset on READ\n    extend,\n)\n```\n\n### Add Data to Cache\n\nAdding to the cache uses a simple key/value pattern for setting data. There are\ntwo functions for adding data to the cache. The standard method `Set` uses the\ncache's configured default timeout.\n\n`err := cache.Set(ctx, key, value)`\n\nThe `SetTTL` method uses the timeout (`time.Duration`) that is passed into the\nmethod for configuring how long the cache should hold the data before it's\ncleared from memory.\n\n`err := cache.SetTTL(ctx, key, value, timeout)`\n\n### Get Data from Cache\n\nGetting data from the cache follows a fairly standard pattern which is similar\not the `sync.Map` get method.\n\n`value, exists := cache.Get(ctx, key)`\n\nThe Get method returns the value (if it exists) and a boolean which indicates if\na value was retrieved from the cache.\n\n### Delete Data from Cache\n\nAs with Get, Delete uses a similar pattern to `sync.Map`.\n\n`cache.Delete(ctx, key)`\n\nThis deletes the key from the map as well as shuts down the backend routines\nrunning that key's processing.\n\n## Benchmarks\n\nTo execute the benchmarks, run the following command:\n\n```bash\n    go test -bench=. ./...\n```\n\nTo view benchmarks over time for the `main` branch of the repository they can\nbe seen on our [Benchmark Report Card].\n\n[Benchmark Report Card]: https://devnw.github.io/ttl/dev/bench\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnw%2Fttl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevnw%2Fttl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnw%2Fttl/lists"}