Skip to content
Snippets Groups Projects

Broadcast message stale cache on different Gitlab revisions

All threads resolved!
Compare and Show latest version
2 files
+ 23
3
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 15
2
@@ -49,7 +49,14 @@ def read(key, klass = nil)
end
def write(key, value, options = nil)
value = { single_strategy_key_component => value } if @nested_key
# We need to 'append write' when fetch calls this
# else the writes will key removing each revision's other's cache entries
if @nested_key
existing_value = existing_cache(key)
existing_value[single_strategy_key_component] = value
value = existing_value
end
backend.write(cache_key(key), value.to_json, options)
end
@@ -68,6 +75,12 @@ def fetch(key, options = {}, &block)
private
def existing_cache(key)
Gitlab::Json.parse(backend.read(cache_key(key)).to_s)
rescue JSON::ParserError
{}
end
def parse_value(raw, klass)
value = Gitlab::Json.parse(raw.to_s)
value = value[single_strategy_key_component] if @nested_key
@@ -91,7 +104,7 @@ def parse_entry(raw, klass)
return klass.new(raw) unless klass.ancestors.include?(ActiveRecord::Base)
# When the cached value is a persisted instance of ActiveRecord::Base in
# some cases a relation can return an empty collection becauses scope.none!
# some cases a relation can return an empty collection because scope.none!
# is being applied on ActiveRecord::Associations::CollectionAssociation#scope
# when the new_record? method incorrectly returns false.
#
Loading