{"id":18677248,"url":"https://github.com/elixir-toniq/mentat","last_synced_at":"2025-04-05T11:12:34.055Z","repository":{"id":44775118,"uuid":"252891432","full_name":"elixir-toniq/mentat","owner":"elixir-toniq","description":"super simple caching with ttls","archived":false,"fork":false,"pushed_at":"2024-02-16T03:51:04.000Z","size":63,"stargazers_count":108,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-01T12:25:26.419Z","etag":null,"topics":["cache","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/elixir-toniq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-04-04T02:39:24.000Z","updated_at":"2024-06-19T19:18:00.458Z","dependencies_parsed_at":"2024-06-19T19:17:54.928Z","dependency_job_id":"93375463-6eb0-44ab-8b96-1f2fa059acad","html_url":"https://github.com/elixir-toniq/mentat","commit_stats":null,"previous_names":["keathley/mentat"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-toniq%2Fmentat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-toniq%2Fmentat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-toniq%2Fmentat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-toniq%2Fmentat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-toniq","download_url":"https://codeload.github.com/elixir-toniq/mentat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325695,"owners_count":20920714,"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","elixir"],"created_at":"2024-11-07T09:33:09.279Z","updated_at":"2025-04-05T11:12:34.027Z","avatar_url":"https://github.com/elixir-toniq.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mentat\n\n\u003c!--MDOC !--\u003e\n\n[![Elixir CI](https://github.com/keathley/mentat/workflows/Elixir%20CI/badge.svg)](https://github.com/keathley/mentat/actions)\n[![Module Version](https://img.shields.io/hexpm/v/mentat.svg)](https://hex.pm/packages/mentat)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/mentat/)\n[![Total Download](https://img.shields.io/hexpm/dt/mentat.svg)](https://hex.pm/packages/mentat)\n[![License](https://img.shields.io/hexpm/l/mentat.svg)](https://github.com/keathley/mentat/blob/main/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/keathley/mentat.svg)](https://github.com/keathley/mentat/commits/main)\n\nProvides a super simple cache with ttls.\n\n## Usage\n\nA cache must be given a name when its started.\n\n```elixir\nMentat.start_link(name: :my_cache)\n```\n\nAfter its been started you can store and retrieve values:\n\n```elixir\nMentat.put(:my_cache, user_id, user)\nuser = Mentat.get(:my_cache, user_id)\n```\n\n## TTLs\n\nBoth `put` and `fetch` operations allow you to specify the key's TTL. If no\nTTL is provided then the TTL is set to `:infinity`. TTL times are always\nin milliseconds.\n\n```elixir\nMentat.put(:my_cache, :key, \"value\", [ttl: 5_000])\n\nMentat.fetch(:my_cache, :key, [ttl: 5_000], fn key -\u003e\n  {:commit, \"value\"}\nend)\n```\n\n### Default TTLs\n\nYou can set a global TTL for all new keys\n\n## Limits\n\nMentat supports optional limits per cache.\n\n```elixir\nMentat.start_link(name: LimitedCache, limit: [size: 100])\n```\n\nWhen the limit is reached, the janitor will asynchronously reclaim a percentage of the keys.\n\n## Telemetry\n\nMentat publishes multiple telemetry events.\n\n  * `[:mentat, :get]` - executed after retrieving a value from the cache.\n    Measurements are:\n\n    * `:status` - Can be either `:hit` or `:miss` depending on if the key was\n      found in the cache.\n\n    Metadata are:\n\n      * `:key` - The key requested\n      * `:cache` - The cache name\n\n  * `[:mentat, :put]` - executed when putting a key into the cache. No\n    measurements are provided.\n\n    Metadata are:\n\n      * `:key` - The key requested\n      * `:cache` - The name of the cache\n\n  * `[:mentat, :janitor, :cleanup]` - executed after old keys are cleaned\n    from the cache. Measurements are:\n\n    * `:duration` - the time it took to clean up the old keys. Time is\n      in `:native` units.\n    * `total_removed_keys` - The count of keys removed from the cache.\n\n    Metadata are:\n\n      * `cache` - The cache name.\n\n## Contracts\n\nMentat supports `Oath` contracts. This helps ensure that you're using Mentat correctly\nand that Mentat is returning what you expect. You can enable contracts by setting\n\n```elixir\nconfig :oath,\n  enable_contracts: true\n```\n\nAnd then recompiling Mentat in dev and test environments:\n\n```\nMIX_ENV=dev mix deps.compile mentat --force\nMIX_ENV=test mix deps.compile mentat --force\n```\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:mentat, \"~\u003e 0.7\"}\n  ]\nend\n```\n\n## Should I use this?\n\nThere are (many) other caching libraries out there that provide many more features\nthan Mentat. But, it turns out, I don't need most of those features. Mentat is\nintended to be very small while still providing the necessary components. The\ntest suite is sparse, but we've been using this implementation in production\nfor a while now so I feel pretty confident in it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-toniq%2Fmentat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-toniq%2Fmentat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-toniq%2Fmentat/lists"}