@@ -312,22 +312,13 @@ template <typename Allocator>
312312void Cache<Allocator>::enableConsistencyCheck(
313313 const std::vector<std::string>& keys) {
314314 XDCHECK (valueTracker_ == nullptr );
315- XDCHECK (!valueValidatingEnabled ());
316315 valueTracker_ =
317316 std::make_unique<ValueTracker>(ValueTracker::wrapStrings (keys));
318317 for (const std::string& key : keys) {
319318 invalidKeys_[key] = false ;
320319 }
321320}
322321
323- template <typename Allocator>
324- void Cache<Allocator>::enableValueValidating(
325- const std::string &expectedValue) {
326- XDCHECK (!valueValidatingEnabled ());
327- XDCHECK (!consistencyCheckEnabled ());
328- this ->expectedValue_ = expectedValue;
329- }
330-
331322template <typename Allocator>
332323typename Cache<Allocator>::RemoveRes Cache<Allocator>::remove(Key key) {
333324 if (!consistencyCheckEnabled ()) {
@@ -421,17 +412,15 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::insertOrReplace(
421412}
422413
423414template <typename Allocator>
424- void Cache<Allocator>::validateValue(const ItemHandle &it) const {
425- XDCHECK (valueValidatingEnabled ());
426-
427- const auto &expected = expectedValue_.value ();
415+ void Cache<Allocator>::touchValue(const ItemHandle& it) const {
416+ XDCHECK (touchValueEnabled ());
428417
429418 auto ptr = reinterpret_cast <const uint8_t *>(getMemory (it));
430- auto cmp = std::memcmp (ptr, expected. data (), std::min< size_t >(expected. size (),
431- getSize (it)));
432- if (cmp != 0 ) {
433- throw std::runtime_error ( " Value does not match! " );
434- }
419+
420+ /* The accumulate call is intended to access all bytes of the value
421+ * and nothing more. */
422+ auto sum = std::accumulate (ptr, ptr + getSize (it), 0ULL );
423+ folly::doNotOptimizeAway (sum);
435424}
436425
437426template <typename Allocator>
@@ -461,8 +450,6 @@ typename Cache<Allocator>::ItemHandle Cache<Allocator>::find(Key key,
461450 return it;
462451 }
463452
464- XDCHECK (!valueValidatingEnabled ());
465-
466453 auto opId = valueTracker_->beginGet (key);
467454 auto it = findFn ();
468455 if (checkGet (opId, it)) {
0 commit comments