@@ -3575,7 +3575,7 @@ protected function purgeCachedDocumentInternal(string $collectionId, ?string $id
35753575 );
35763576 }
35773577
3578- $ this ->cache ->purge ($ documentKey );
3578+ $ this ->withRetries ( fn () => $ this -> cache ->purge ($ documentKey) );
35793579
35803580 return true ;
35813581 }
@@ -3757,26 +3757,29 @@ private function advanceDocumentCacheEpoch(string $collectionKey, string $defini
37573757 * epoch, so readers refill it with the tombstone. A write whose registration keeps failing
37583758 * still blocks with its tombstone: its activation finishes it while the tombstone is its own,
37593759 * and otherwise retires whatever readers filled while it ran. An epoch that cannot be read is
3760- * purged all the same, so a cache that cannot confirm the purge fails the write.
3760+ * purged all the same, so a cache that cannot confirm the purge fails the write. Each step is
3761+ * retried first, so a blip shorter than the retries does not cost the write.
37613762 */
37623763 private function blockDocumentCacheEpoch (string $ collectionKey , string $ token , string $ definitionKey ): bool
37633764 {
37643765 $ epochKey = $ collectionKey .'#epoch ' ;
37653766 if (! $ this ->registerDocumentCacheOwner ($ collectionKey , $ token )) {
37663767 $ epoch = $ this ->cache ->load ($ epochKey , self ::DOCUMENT_CACHE_PERMANENT );
37673768 if ($ epoch === false || $ epoch === null ) {
3768- $ this ->cache ->purge ($ epochKey );
3769+ $ this ->withRetries ( fn () => $ this -> cache ->purge ($ epochKey) );
37693770
37703771 return false ;
37713772 }
37723773 }
37733774
3774- if ($ this ->cache ->save ($ epochKey , self ::DOCUMENT_CACHE_BLOCKED_PREFIX .$ token .self ::DOCUMENT_CACHE_SEPARATOR .\time ()) === false ) {
3775- throw new RuntimeException ("Failed to block document cache epoch ' {$ epochKey }' " );
3776- }
3775+ $ this ->withRetries (function () use ($ epochKey , $ token ): void {
3776+ if ($ this ->cache ->save ($ epochKey , self ::DOCUMENT_CACHE_BLOCKED_PREFIX .$ token .self ::DOCUMENT_CACHE_SEPARATOR .\time ()) === false ) {
3777+ throw new RuntimeException ("Failed to block document cache epoch ' {$ epochKey }' " );
3778+ }
3779+ });
37773780
3778- $ this ->cache ->purge ($ collectionKey .'#started ' );
3779- $ this ->purgeCachedDefinition ($ definitionKey );
3781+ $ this ->withRetries ( fn () => $ this -> cache ->purge ($ collectionKey .'#started ' ) );
3782+ $ this ->withRetries ( fn () => $ this -> purgeCachedDefinition ($ definitionKey) );
37803783
37813784 return true ;
37823785 }
0 commit comments