Skip to content

Commit 2d48fcb

Browse files
committed
Drop auth cache prefixes
As the auth caches are no now internal we do not need the extra key prefixes. The prefixes were meant to simply reduce key name collisions; which being an internal cache is not an issue.
1 parent 09bb783 commit 2d48fcb

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

lib/kracken/authenticator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def self.user_with_token(token)
3434
# for the user, set it to nil, fetch from cache and only query if there
3535
# was a cache-hit (thus user is still nil).
3636
user = nil
37-
user_id = Authenticator.cache.fetch("auth/#{token}/#{auth.etag}") {
37+
user_id = Authenticator.cache.fetch("#{token}/#{auth.etag}") {
3838
user = self.new(auth.body).to_app_user
3939
user.id
4040
}

lib/kracken/controllers/token_authenticatable.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,19 @@ def request_http_token_authentication(realm = 'Application')
3636

3737
module_function
3838

39-
TOKEN_AUTH_CACHE_PREFIX = "auth/token/"
40-
4139
def cache_valid_auth(token, force: false, &generate_cache)
42-
cache_key = TOKEN_AUTH_CACHE_PREFIX + token
40+
cache_key = token
4341
val = TokenAuthenticatable.cache.read(cache_key) unless force
4442
val ||= store_valid_auth(cache_key, &generate_cache)
4543
shallow_freeze(val)
4644
end
4745

4846
def clear_auth_cache
49-
TokenAuthenticatable.cache.delete_matched TOKEN_AUTH_CACHE_PREFIX + "*"
47+
TokenAuthenticatable.cache.clear
5048
end
5149

5250
def shallow_freeze(val)
53-
# `nil` is frozen in Ruby 2.2 but not in Ruby 2.1
54-
return val if val.frozen? || val.nil?
51+
return val if val.frozen?
5552
val.each { |_k, v| v.freeze }.freeze
5653
end
5754

spec/kracken/controllers/token_authenticatable_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def authenticate_or_request_with_http_token(realm = nil)
6565
}
6666
}
6767
let(:cached_token) { "any token" }
68-
let(:cache_key) { "auth/token/any token" }
68+
let(:cache_key) { "any token" }
6969

7070
before do
7171
a_controller.request.env = {
@@ -163,7 +163,7 @@ def authenticate_or_request_with_http_token(realm = nil)
163163
expect {
164164
a_controller.authenticate_user_with_token!
165165
}.not_to change {
166-
Controllers::TokenAuthenticatable.cache.exist?("auth/token/#{invalid_token}")
166+
Controllers::TokenAuthenticatable.cache.exist?("#{invalid_token}")
167167
}.from false
168168
end
169169
end
@@ -222,7 +222,7 @@ def authenticate_or_request_with_http_token(realm = nil)
222222
expect {
223223
a_controller.authenticate_user_with_token!
224224
}.to change {
225-
Controllers::TokenAuthenticatable.cache.read("auth/token/any token")
225+
Controllers::TokenAuthenticatable.cache.read("any token")
226226
}.from(nil).to(
227227
id: :any_id,
228228
team_ids: [:some, :team, :ids],
@@ -231,7 +231,7 @@ def authenticate_or_request_with_http_token(realm = nil)
231231

232232
it "sets the cache expiration to one minute by default" do
233233
expect(Controllers::TokenAuthenticatable.cache).to receive(:write).with(
234-
"auth/token/any token",
234+
"any token",
235235
anything,
236236
include(expires_in: 1.minute),
237237
)

0 commit comments

Comments
 (0)