Class: Gitlab::ExternalAuthorization::Cache
- Inherits:
-
Object
- Object
- Gitlab::ExternalAuthorization::Cache
- Defined in:
- lib/gitlab/external_authorization/cache.rb
Constant Summary collapse
- VALIDITY_TIME =
6.hours
Instance Method Summary collapse
-
#initialize(user, label) ⇒ Cache
constructor
A new instance of Cache.
- #load ⇒ Object
- #store(new_access, new_reason, new_refreshed_at) ⇒ Object
Constructor Details
#initialize(user, label) ⇒ Cache
Returns a new instance of Cache.
8 9 10 11 |
# File 'lib/gitlab/external_authorization/cache.rb', line 8 def initialize(user, label) @user = user @label = label end |
Instance Method Details
#load ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gitlab/external_authorization/cache.rb', line 13 def load @access, @reason, @refreshed_at = with_redis do |redis| redis.hmget(cache_key, :access, :reason, :refreshed_at) end [access, reason, refreshed_at] end |
#store(new_access, new_reason, new_refreshed_at) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/external_authorization/cache.rb', line 21 def store(new_access, new_reason, new_refreshed_at) with_redis do |redis| redis.pipelined do |pipeline| pipeline.mapped_hmset( cache_key, { access: new_access.to_s, reason: new_reason.to_s, refreshed_at: new_refreshed_at.to_s } ) pipeline.expire(cache_key, VALIDITY_TIME) end end end |