{"id":22210518,"url":"https://github.com/nicolab/crystal-lru-cache","last_synced_at":"2025-07-27T10:31:47.189Z","repository":{"id":78147756,"uuid":"342781778","full_name":"Nicolab/crystal-lru-cache","owner":"Nicolab","description":":gem: key/value LRU cache that supports lifecycle, global size limit and expiration time.","archived":false,"fork":false,"pushed_at":"2021-03-26T19:18:07.000Z","size":42,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T09:16:35.802Z","etag":null,"topics":["cache","crystal","crystal-lang","kv","kv-store","lru","lru-cache","store"],"latest_commit_sha":null,"homepage":"https://nicolab.github.io/crystal-lru-cache/","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nicolab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"Nicolab","patreon":"nicolab","custom":"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC"}},"created_at":"2021-02-27T05:48:47.000Z","updated_at":"2024-09-14T14:29:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8945921-7a46-44ac-9491-5df3d98d13d5","html_url":"https://github.com/Nicolab/crystal-lru-cache","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Nicolab/crystal-lru-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-lru-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-lru-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-lru-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-lru-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nicolab","download_url":"https://codeload.github.com/Nicolab/crystal-lru-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-lru-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267345019,"owners_count":24072439,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","crystal","crystal-lang","kv","kv-store","lru","lru-cache","store"],"created_at":"2024-12-02T20:12:58.536Z","updated_at":"2025-07-27T10:31:47.184Z","avatar_url":"https://github.com/Nicolab.png","language":"Crystal","funding_links":["https://github.com/sponsors/Nicolab","https://patreon.com/nicolab","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC"],"categories":[],"sub_categories":[],"readme":"# LRU cache\n\n[![CI Status](https://github.com/Nicolab/crystal-lru-cache/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-lru-cache/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-lru-cache.svg)](https://github.com/Nicolab/crystal-lru-cache/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-lru-cache/)\n\n:gem: Key/value LRU cache that supports lifecycle, global size limit and expiration time.\n\n\u003e LRU: Least Recently Used\n\n_lru-cache_ supports lifecycle, a global item size limit and an expiration time can be set for each item independently.\n\nIf a *max_size* is defined, the LRU cache can only contain *max_size* items.\nBeyond *max_size*, items are deleted from the oldest to the most recently used.\n\nA caching system is a vital part, it must be simple to use, reliable and efficient. _lru-cache_ is battle tested 👌\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\n   dependencies:\n     lru-cache:\n       github: nicolab/crystal-lru-cache\n       version: ~\u003e 1.0.3 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"lru-cache\"\n\ncache = LRUCache(String, String).new(max_size: 10_000)\n\ncache.set(\"hello\", \"Hello Crystal!\")\nputs cache.get(\"hello\") # =\u003e \"Hello Crystal!\"\n\n# or\nputs cache[\"hello\"] # =\u003e \"Hello Crystal!\"\n\nputs cache.has?(\"hello\") # =\u003e true\n\n# Time limit\ncache.set(\"hello\", \"Hello Crystal!\", Time.utc + 1.hour)\n\nputs cache.expire_at \"hello\" # =\u003e Time.utc + 1.hour\n\n# Deletes \"hello\" item\ncache.delete \"hello\"\n\n# Empties the cache\ncache.clear\n```\n\nLifecycle:\n\n```crystal\nrequire \"lru-cache\"\n\nclass Cache(K, V) \u003c LRUCache(K, V)\n  # Optional lifecycle method to be executed after setting an item (`add!` and `set`).\n  private def after_set(key : K, item : Tuple(V, Time?))\n    puts \"after_set: #{key}\"\n    pp item\n  end\n\n  # Optional lifecycle method to be executed after deleting an item (`delete`).\n  private def after_delete(key : K, item : Tuple(V, Time?)?)\n    puts \"after_delete: #{key}\"\n    pp item\n  end\n\n  # Optional lifecycle method to be executed after clearing all the cache (`clear`).\n  private def after_clear\n    puts \"after_clear\"\n  end\nend\n\ncache = Cache(String, String).new(max_size: 10_000)\n\ncache.set(\"hello\", \"Hello Crystal!\")\ncache.set(\"foo\", \"bar\")\ncache.delete(\"foo\")\ncache.clear\n```\n\n📘 [API doc](https://nicolab.github.io/crystal-lru-cache/)\n\n## Development\n\nInstall dev dependencies:\n\n```sh\nshards install\n```\n\nRun:\n\n```sh\ncrystal spec\n```\n\nClean before commit:\n\n```sh\ncrystal tool format\n./bin/ameba\n```\n\n## Contributing\n\n1. Fork it (https://github.com/Nicolab/crystal-lru-cache/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-lru-cache/blob/master/LICENSE) (c) 2021, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolab%2Fcrystal-lru-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolab%2Fcrystal-lru-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolab%2Fcrystal-lru-cache/lists"}