{"action":"created","issue":{"url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/272","labels_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/272/labels{/name}","comments_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/272/comments","events_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/272/events","html_url":"https://github.com/lynndylanhurley/devise_token_auth/pull/272","id":89089032,"number":272,"title":"perf(token_is_current?): add simplistic cache to reduce overhead of redundant token checks during validation calls","user":{"login":"booleanbetrayal","id":981825,"avatar_url":"https://avatars.githubusercontent.com/u/981825?v=3","gravatar_id":"","url":"https://api.github.com/users/booleanbetrayal","html_url":"https://github.com/booleanbetrayal","followers_url":"https://api.github.com/users/booleanbetrayal/followers","following_url":"https://api.github.com/users/booleanbetrayal/following{/other_user}","gists_url":"https://api.github.com/users/booleanbetrayal/gists{/gist_id}","starred_url":"https://api.github.com/users/booleanbetrayal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/booleanbetrayal/subscriptions","organizations_url":"https://api.github.com/users/booleanbetrayal/orgs","repos_url":"https://api.github.com/users/booleanbetrayal/repos","events_url":"https://api.github.com/users/booleanbetrayal/events{/privacy}","received_events_url":"https://api.github.com/users/booleanbetrayal/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-06-17T18:20:55Z","updated_at":"2015-06-18T13:40:52Z","closed_at":"2015-06-18T01:37:06Z","pull_request":{"url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/pulls/272","html_url":"https://github.com/lynndylanhurley/devise_token_auth/pull/272","diff_url":"https://github.com/lynndylanhurley/devise_token_auth/pull/272.diff","patch_url":"https://github.com/lynndylanhurley/devise_token_auth/pull/272.patch"},"body":"Within `DeviseTokenAuth::Concerns::User#token_is_valid?` we're seeing the `BCrypt::Password.new(token_hash)` + string comparison (casting) operation itself take approximately 75ms on average when validating tokens, which makes it hard / impossible to reach our goal of < 200ms response times for request handling. \r\n\r\nThis PR adds a very simplistic caching mechanism that will lookup the check value, saving unnecessary overhead on redundant token / hash checks. It can be iterated on further if a more robust caching implementation is needed / desired. \r\n\r\nThis will primarily benefit environments where `change_headers_on_each_request` is disabled, but will still help requests that occur within the `batch_request_buffer_throttle` threshold.\r\n\r\nThanks to @nbrustein for the implementation."},"comment":{"url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/comments/113160742","html_url":"https://github.com/lynndylanhurley/devise_token_auth/pull/272#issuecomment-113160742","issue_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/272","id":113160742,"user":{"login":"booleanbetrayal","id":981825,"avatar_url":"https://avatars.githubusercontent.com/u/981825?v=3","gravatar_id":"","url":"https://api.github.com/users/booleanbetrayal","html_url":"https://github.com/booleanbetrayal","followers_url":"https://api.github.com/users/booleanbetrayal/followers","following_url":"https://api.github.com/users/booleanbetrayal/following{/other_user}","gists_url":"https://api.github.com/users/booleanbetrayal/gists{/gist_id}","starred_url":"https://api.github.com/users/booleanbetrayal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/booleanbetrayal/subscriptions","organizations_url":"https://api.github.com/users/booleanbetrayal/orgs","repos_url":"https://api.github.com/users/booleanbetrayal/repos","events_url":"https://api.github.com/users/booleanbetrayal/events{/privacy}","received_events_url":"https://api.github.com/users/booleanbetrayal/received_events","type":"User","site_admin":false},"created_at":"2015-06-18T13:40:52Z","updated_at":"2015-06-18T13:40:52Z","body":"Thanks to @nbrustein  =]"}}