lib/wcc/contentful/middleware/store/caching_middleware.rb in wcc-contentful-1.4.0.rc1 vs lib/wcc/contentful/middleware/store/caching_middleware.rb in wcc-contentful-1.4.0.rc2

- old
+ new

@@ -32,11 +32,12 @@ # If what we found in the cache is for the wrong Locale, go hit the store directly. # Now that the one locale is in the cache, when we index next time we'll index the # all-locales version and we'll be fine. locale = options[:locale]&.to_s || default_locale - if found.dig('sys', 'locale') != locale + found_locale = found.dig('sys', 'locale')&.to_s + if found_locale && (found_locale != locale) event = 'miss' return store.find(key, **options) end found @@ -88,18 +89,24 @@ def _index(json) ensure_hash(json) id = json.dig('sys', 'id') type = json.dig('sys', 'type') prev = @cache.read(id) - return if prev.nil? && LAZILY_CACHEABLE_TYPES.include?(type) + if prev.nil? && LAZILY_CACHEABLE_TYPES.include?(type) + _instrument('miss.index', key: id, type: type, prev: nil, next: nil) + return + end if (prev_rev = prev&.dig('sys', 'revision')) && (next_rev = json.dig('sys', 'revision')) && (next_rev < prev_rev) + _instrument('miss.index', key: id, type: type, prev: prev_rev, next: next_rev) return prev end # we also set DeletedEntry objects in the cache - no need to go hit the API when we know # this is a nil object - @cache.write(id, json, expires_in: expires_in) + _instrument('write.index', key: id, type: type, prev: prev_rev, next: next_rev) do + @cache.write(id, json, expires_in: expires_in) + end case type when 'DeletedEntry', 'DeletedAsset' _instrument 'delete', id: id nil