{"id":17036122,"url":"https://github.com/digaev/stale_options","last_synced_at":"2025-06-20T07:33:31.308Z","repository":{"id":54229780,"uuid":"140149246","full_name":"digaev/stale_options","owner":"digaev","description":"A Ruby gem for caching HTTP responses.","archived":false,"fork":false,"pushed_at":"2023-03-23T05:30:36.000Z","size":37,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T12:52:20.466Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/digaev/stale_options","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/digaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2018-07-08T08:09:02.000Z","updated_at":"2023-03-17T03:07:28.000Z","dependencies_parsed_at":"2025-04-14T11:45:41.856Z","dependency_job_id":null,"html_url":"https://github.com/digaev/stale_options","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/digaev/stale_options","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digaev%2Fstale_options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digaev%2Fstale_options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digaev%2Fstale_options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digaev%2Fstale_options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digaev","download_url":"https://codeload.github.com/digaev/stale_options/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digaev%2Fstale_options/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260901195,"owners_count":23079723,"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":[],"created_at":"2024-10-14T08:49:26.151Z","updated_at":"2025-06-20T07:33:26.300Z","avatar_url":"https://github.com/digaev.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StaleOptions\n\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/digaev/stale_options/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/digaev/stale_options/tree/master)\n[![Coverage Status](https://coveralls.io/repos/github/digaev/stale_options/badge.svg?branch=master)](https://coveralls.io/github/digaev/stale_options?branch=master)\n[![Gem Version](https://badge.fury.io/rb/stale_options.svg)](https://badge.fury.io/rb/stale_options)\n\nA gem for caching HTTP responses.\n\nThe gem was built with an idea to implement a class which will create options for the `ActionController::ConditionalGet#stale?` method. It allows to cache any kind of objects, not only records or collections (unlike of `#stale?`).\n\n___\n\n* [Installation](#installation)\n* [Usage](#usage)\n  * [Caching options](#caching-options)\n  * [Examples](#examples)\n  * [Controller helpers](#controller-helpers)\n* [Contributing](#contributing)\n* [License](#license)\n\n## Installation\n\nAdd one of these lines to your application's Gemfile depending on your Rails version:\n\n```ruby\n# Rails 5.2\ngem 'stale_options', '~\u003e 1.0.0'\n\n# Rails 6.0\ngem 'stale_options', '~\u003e 1.1.0'\n\n# Rails 6.1\ngem 'stale_options', '~\u003e 1.2.0'\n\n# Rails 7.0\ngem 'stale_options', '~\u003e 1.3.0'\n```\n\nAnd then execute:\n\n```sh\nbundle install\n```\n\n## Usage\n\n```\nStaleOptions.create(Item.all)\n=\u003e {:etag=\u003e\"39f08c583b023142dd64b0922dfaefd4\", :last_modified=\u003e2018-07-04 18:05:22 UTC}\n```\n\nThe method accepts an optional second parameter (see Caching options).\n\n### Caching options\n\nThere are two options for caching, `cache_by` and `last_modified`:\n\n* `:cache_by`\n  * `String` or `Symbol`. The name of the method that returns the unique identifier of the object for caching, which is used to set `etag` of the resulting options. Set it to `itself` if you don't have such a method (see example below) and the gem will generate `etag` for you.\n  * Default: `:updated_at`.\n* `:last_modified`\n  * `String` or `Symbol`. The name of the method that returns an instance of `ActiveSupport::TimeWithZone`, `DateTime` or `Time`.\n  * `ActiveSupport::TimeWithZone`, `DateTime`, `Time` or `nil` to set `:last_modified` directly.\n  * Default: `:updated_at`.\n\n### Examples\n\n```\nStaleOptions.create(Task.all, last_modified: :done_at)\n=\u003e {:etag=\u003e\"ce8d2fbc9b815937b59e8815d8a85c21\", :last_modified=\u003e2018-06-30 18:25:07 UTC}\n\nStaleOptions.create([1, 2, 3], cache_by: :itself, last_modified: nil)\n=\u003e {:etag=\u003e\"73250e72da5d8950b6bbb16044353d26\", :last_modified=\u003enil}\n\nStaleOptions.create({ a: 'a', b: 'b', c: 'c' }, cache_by: :itself, last_modified: Time.now)\n=\u003e {:etag=\u003e\"fec76eca1192bc7371e44d517b56c93f\", :last_modified=\u003e2018-07-08 07:08:48 UTC}\n```\n\n### Controller helpers\n\nIn your controller:\n\n```ruby\n# To render a template:\n\nclass PostsController \u003c ApplicationController\n  include StaleOptions::Backend\n\n  def index\n    if_stale?(Post.all) do |posts|\n      @posts = posts\n    end\n  end\nend\n\n# Or, to render json:\n\nclass PostsController \u003c ApplicationController\n  include StaleOptions::Backend\n\n  def index\n    if_stale?(Post.all) do |posts|\n      render json: posts\n    end\n  end\nend\n```\n\nHere we're using the `#if_stale?` method which was added to the controller by including the `StaleOptions::Backend` module. The method accepts two arguments `record` and `options` (yeah, just like `StaleOptions.create`).\n\nUnder the hood, it calls `ActionController::ConditionalGet#stale?` with options created by `StaleOptions.create`:\n\n```ruby\ndef if_stale?(record, options = {})\n  yield(record) if stale?(StaleOptions.create(record, options))\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/digaev/stale_options.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigaev%2Fstale_options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigaev%2Fstale_options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigaev%2Fstale_options/lists"}