{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/20913","labels_url":"https://api.github.com/repos/rails/rails/issues/20913/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/20913/comments","events_url":"https://api.github.com/repos/rails/rails/issues/20913/events","html_url":"https://github.com/rails/rails/pull/20913","id":95637884,"number":20913,"title":"[ActiveSupport] Add ability to use `Proc` as 'expires_in' key","user":{"login":"avokhmin","id":422109,"avatar_url":"https://avatars.githubusercontent.com/u/422109?v=3","gravatar_id":"","url":"https://api.github.com/users/avokhmin","html_url":"https://github.com/avokhmin","followers_url":"https://api.github.com/users/avokhmin/followers","following_url":"https://api.github.com/users/avokhmin/following{/other_user}","gists_url":"https://api.github.com/users/avokhmin/gists{/gist_id}","starred_url":"https://api.github.com/users/avokhmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avokhmin/subscriptions","organizations_url":"https://api.github.com/users/avokhmin/orgs","repos_url":"https://api.github.com/users/avokhmin/repos","events_url":"https://api.github.com/users/avokhmin/events{/privacy}","received_events_url":"https://api.github.com/users/avokhmin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-17T11:14:18Z","updated_at":"2015-07-18T21:28:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/20913","html_url":"https://github.com/rails/rails/pull/20913","diff_url":"https://github.com/rails/rails/pull/20913.diff","patch_url":"https://github.com/rails/rails/pull/20913.patch"},"body":"Sometimes calculation of `expires_in` can spend a lot of time, so, will be great to do it only if it needed.\r\n\r\nRelated with: https://github.com/mperham/dalli/pull/531"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/122598000","html_url":"https://github.com/rails/rails/pull/20913#issuecomment-122598000","issue_url":"https://api.github.com/repos/rails/rails/issues/20913","id":122598000,"user":{"login":"avokhmin","id":422109,"avatar_url":"https://avatars.githubusercontent.com/u/422109?v=3","gravatar_id":"","url":"https://api.github.com/users/avokhmin","html_url":"https://github.com/avokhmin","followers_url":"https://api.github.com/users/avokhmin/followers","following_url":"https://api.github.com/users/avokhmin/following{/other_user}","gists_url":"https://api.github.com/users/avokhmin/gists{/gist_id}","starred_url":"https://api.github.com/users/avokhmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avokhmin/subscriptions","organizations_url":"https://api.github.com/users/avokhmin/orgs","repos_url":"https://api.github.com/users/avokhmin/repos","events_url":"https://api.github.com/users/avokhmin/events{/privacy}","received_events_url":"https://api.github.com/users/avokhmin/received_events","type":"User","site_admin":false},"created_at":"2015-07-18T21:28:24Z","updated_at":"2015-07-18T21:28:24Z","body":"> Can you give an example of a complex expires_in calculation?\r\n\r\n@matthewd example:\r\n\r\n```\r\nclass MyService\r\n\r\n  # Private: Expiration time of something.\r\n  EXPIRATION = 1.day\r\n\r\n  # Public: Get all user some keys.\r\n  def some_keys\r\n    return [] if member.new_record?\r\n\r\n    Rails.cache.fetch(['MyService#some_keys', member], expires_in: -> { some_keys_expiration }) do\r\n      ...\r\n    end\r\n  end\r\n\r\n  private\r\n\r\n  # Private: Get expiration time based on last something time.\r\n  def some_keys_expiration\r\n    return unless member.something_once_per_day?\r\n    time = member.something.maximum(:last_something_at)\r\n    if time\r\n      now   = Time.now\r\n      time += EXPIRATION\r\n      time - now if time > now\r\n    end\r\n  end\r\n```\r\n\r\nIn this case we should do extra requests to DB for calculation of `expires_in`."}}