diff options
Diffstat (limited to 'app/models/concerns/redis_cacheable.rb')
-rw-r--r-- | app/models/concerns/redis_cacheable.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/concerns/redis_cacheable.rb b/app/models/concerns/redis_cacheable.rb index 2d4ed51ce3b..f1d29ad5a90 100644 --- a/app/models/concerns/redis_cacheable.rb +++ b/app/models/concerns/redis_cacheable.rb @@ -26,8 +26,8 @@ module RedisCacheable end def cache_attributes(values) - Gitlab::Redis::Cache.with do |redis| - redis.set(cache_attribute_key, values.to_json, ex: CACHED_ATTRIBUTES_EXPIRY_TIME) + with_redis do |redis| + redis.set(cache_attribute_key, Gitlab::Json.dump(values), ex: CACHED_ATTRIBUTES_EXPIRY_TIME) end clear_memoization(:cached_attributes) @@ -41,13 +41,17 @@ module RedisCacheable def cached_attributes strong_memoize(:cached_attributes) do - Gitlab::Redis::Cache.with do |redis| + with_redis do |redis| data = redis.get(cache_attribute_key) Gitlab::Json.parse(data, symbolize_names: true) if data end end end + def with_redis(&block) + Gitlab::Redis::Cache.with(&block) # rubocop:disable CodeReuse/ActiveRecord + end + def cast_value_from_cache(attribute, value) self.class.type_for_attribute(attribute.to_s).cast(value) end |