{"id":15406748,"url":"https://github.com/dannyben/lightly","last_synced_at":"2025-04-04T16:11:14.480Z","repository":{"id":8765759,"uuid":"59682277","full_name":"DannyBen/lightly","owner":"DannyBen","description":"Ruby file cache for performing heavy tasks, lightly.","archived":false,"fork":false,"pushed_at":"2025-02-05T11:32:50.000Z","size":57,"stargazers_count":40,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T15:04:05.547Z","etag":null,"topics":["cache","cache-control","gem","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/DannyBen.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":"2016-05-25T17:08:23.000Z","updated_at":"2025-03-12T12:10:26.000Z","dependencies_parsed_at":"2024-10-19T12:43:31.722Z","dependency_job_id":null,"html_url":"https://github.com/DannyBen/lightly","commit_stats":{"total_commits":62,"total_committers":2,"mean_commits":31.0,"dds":0.4193548387096774,"last_synced_commit":"8fd7d127ff386204704b8c996a5a37e6c3920bb3"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Flightly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Flightly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Flightly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Flightly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/lightly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208142,"owners_count":20901570,"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","cache-control","gem","ruby"],"created_at":"2024-10-01T16:25:11.633Z","updated_at":"2025-04-04T16:11:14.464Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","readme":"# Lightly - Ruby File Cache\n\n[![Gem Version](https://badge.fury.io/rb/lightly.svg)](https://badge.fury.io/rb/lightly)\n[![Build Status](https://github.com/DannyBen/lightly/workflows/Test/badge.svg)](https://github.com/DannyBen/lightly/actions?query=workflow%3ATest)\n[![Maintainability](https://api.codeclimate.com/v1/badges/8296395c9a332a15afc7/maintainability)](https://codeclimate.com/github/DannyBen/lightly/maintainability)\n\n---\n\nLightly is a file cache for performing heavy tasks, lightly.\n\n---\n\n## Install\n\n```shell\n$ gem install lightly\n```\n\nOr with bundler:\n\n```ruby\ngem 'lightly'\n```\n\n## Usage\n\nLightly can be used both as an instance, and as a static class.\n\n```ruby\nrequire 'lightly'\n\n# Instance\nlightly = Lightly.new life: '3h'\nresponse = lightly.get 'key' do\n  # Heavy operation here\nend\n\n# Static\nLightly.life = '3h'\nresponse = Lightly.get 'key' do\n  # Heavy operation here\nend\n```\n\nThe design intention is to provide both a globally available singleton\n`Lightly` object, as well as multiple caching instances, with different\nsettings - depending on the use case.\n\nNote that the examples in this document are all using the instance syntax,\nbut all methods are also available statically.\n\nThis is the basic usage pattern:\n\n```ruby\nrequire 'lightly'\n\nlightly = Lightly.new\n\ncontent = lightly.get 'key' do\n  # Heavy operation here\n  entire_internet.download\nend\n```\n\nThis will look for a cached object with the given key and return it \nif it exists and not older than 1 hour. Otherwise, it will perform the\noperation inside the block, and save it to the cache object.\n\nBy default, the cached objects are stored in the `./cache` directory, and\nexpire after 60 minutes. The cache directory will be created as needed.\n\nIn addition, the provided key is hashed to its MD5 representation, and the file\npermissions are optionally set.\n\nYou can change these settings on initialization:\n\n```ruby\nlightly = Lightly.new dir: 'tmp/my_cache', life: 7200,\n  hash: false, permissions: 0o640\n```\n\nOr later:\n\n```ruby\nlightly = Lightly.new\nlightly.dir = 'tmp/my_cache'\nlightly.life = '1d'\nlightly.hash = false\nlightly.permissions = 0o640\n```\n\nThe `life` property accepts any of these formats:\n\n```ruby\nlightly.life = 10     # 10 seconds\nlightly.life = '20s'  # 20 seconds\nlightly.life = '10m'  # 10 minutes\nlightly.life = '10h'  # 10 hours\nlightly.life = '10d'  # 10 days\n```\n\nTo check if a key is cached, use the `cached?` method:\n\n```ruby\nlightly = Lightly.new\nlightly.cached? 'example'\n# =\u003e false\n\ncontent = lightly.get 'example' do\n  open('http://example.com').read\nend\n\nlightly.cached? 'example'\n# =\u003e true\n```\n\nYou can enable/disable the cache at any time:\n\n```ruby\nlightly = Lightly.new\nlightly.disable\nlightly.enabled? \n# =\u003e false\n\ncontent = lightly.get 'example' do\n  open('http://example.com').read\nend\n\nlightly.cached? 'example'\n# =\u003e false\n\nlightly.enable\n\ncontent = lightly.get 'example' do\n  open('http://example.com').read\nend\n\nlightly.cached? 'example'\n# =\u003e true\n```\n\nTo flush the cache, call:\n\n```ruby\nlightly = Lightly.new\nlightly.flush\n```\n\nTo clear the cache for a given key, call:\n\n```ruby\nlightly = Lightly.new\nlightly.clear 'example'\n```\n\nTo clear all expired keys, call:\n\n```ruby\nlightly = Lightly.new\nlightly.prune\n```\n\nIf your block returns `false` or `nil`, the data will not be cached:\n\n```ruby\nresult = lightly.get 'test' do\n  false\nend\n\nputs lightly.cached? 'test'\n# =\u003e false\n```\n\n## Related Projects\n\nFor a similar gem that provides caching specifically for HTTP downloads,\nsee the [WebCache gem][webcache].\n\n## Contributing / Support\n\nIf you experience any issue, have a question or a suggestion, or if you wish\nto contribute, feel free to [open an issue][issues].\n\n---\n\n[webcache]: https://github.com/DannyBen/webcache\n[issues]: https://github.com/DannyBen/lightly/issues","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Flightly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Flightly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Flightly/lists"}