Module: RedisCacheable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize
- Included in:
- Ci::Runner, Ci::RunnerManager, Clusters::AgentToken
- Defined in:
- app/models/concerns/redis_cacheable.rb
Constant Summary collapse
- CACHED_ATTRIBUTES_EXPIRY_TIME =
24.hours
Instance Method Summary collapse
- #cache_attributes(values) ⇒ Object
- #cached_attribute(attribute) ⇒ Object
- #merge_cache_attributes(values) ⇒ Object
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) with_redis do |redis| redis.set(cache_attribute_key, Gitlab::Json.dump(values), 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 |
#merge_cache_attributes(values) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/concerns/redis_cacheable.rb', line 36 def merge_cache_attributes(values) existing_attributes = Hash(cached_attributes) merged_attributes = existing_attributes.merge(values.symbolize_keys) return if merged_attributes == existing_attributes cache_attributes(merged_attributes) end |