Module: RedisCacheable

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Utils::StrongMemoize
Included in:
Ci::Runner
Defined in:
app/models/concerns/redis_cacheable.rb

Constant Summary collapse

CACHED_ATTRIBUTES_EXPIRY_TIME =
24.hours

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#cache_attributes(values) ⇒ Object


28
29
30
31
32
33
34
# File 'app/models/concerns/redis_cacheable.rb', line 28

def cache_attributes(values)
  Gitlab::Redis::Cache.with do |redis|
    redis.set(cache_attribute_key, values.to_json, ex: CACHED_ATTRIBUTES_EXPIRY_TIME)
  end

  clear_memoization(:cached_attributes)
end

#cached_attribute(attribute) ⇒ Object


23
24
25
26
# File 'app/models/concerns/redis_cacheable.rb', line 23

def cached_attribute(attribute)
  cached_value = (cached_attributes || {})[attribute]
  cast_value_from_cache(attribute, cached_value) if cached_value
end