@@ -862,6 +862,75 @@ class Doc:
862862 self .assertEqual (2 , len (fired ))
863863 self .store .remove_after_save_changes (on_after )
864864
865+ def test_track_changes_mode_evicts_cache_on_out_of_band_modification (self ):
866+ """End-to-end: under TRACK_CHANGES mode, a modification made through a
867+ second session must invalidate the aggressive cache so that the next
868+ load returns the new value rather than the cached one."""
869+ import time
870+ from ravendb .http .misc import AggressiveCacheMode
871+
872+ class Doc :
873+ def __init__ (self , name = None ):
874+ self .name = name
875+
876+ with self .store .open_session () as session :
877+ session .store (Doc ("v1" ), "docs/track/1" )
878+ session .save_changes ()
879+
880+ with self .store .aggressively_cache_for (
881+ datetime .timedelta (minutes = 5 ), mode = AggressiveCacheMode .TRACK_CHANGES
882+ ):
883+ with self .store .open_session () as session :
884+ self .assertEqual ("v1" , session .load ("docs/track/1" , Doc ).name )
885+
886+ # Out-of-band modification — a fresh executor would not see the
887+ # cached value, but the executor inside this scope still must
888+ # because the Changes API notification evicts the cache entry.
889+ with self .store .open_session () as session :
890+ session .load ("docs/track/1" , Doc ).name = "v2"
891+ session .save_changes ()
892+
893+ deadline = time .time () + 10
894+ observed = None
895+ while time .time () < deadline :
896+ with self .store .open_session () as session :
897+ observed = session .load ("docs/track/1" , Doc ).name
898+ if observed == "v2" :
899+ break
900+ time .sleep (0.1 )
901+
902+ self .assertEqual ("v2" , observed )
903+
904+ def test_do_not_track_changes_serves_cached_value_after_out_of_band_modification (self ):
905+ """End-to-end: under DO_NOT_TRACK_CHANGES, no Changes API subscription
906+ is opened, so an out-of-band modification within the scope is not
907+ observed — the cached value is served for the duration of the scope."""
908+ from ravendb .http .misc import AggressiveCacheMode
909+
910+ class Doc :
911+ def __init__ (self , name = None ):
912+ self .name = name
913+
914+ with self .store .open_session () as session :
915+ session .store (Doc ("v1" ), "docs/notrack/1" )
916+ session .save_changes ()
917+
918+ with self .store .aggressively_cache_for (
919+ datetime .timedelta (minutes = 5 ), mode = AggressiveCacheMode .DO_NOT_TRACK_CHANGES
920+ ):
921+ with self .store .open_session () as session :
922+ self .assertEqual ("v1" , session .load ("docs/notrack/1" , Doc ).name )
923+
924+ with self .store .open_session () as session :
925+ session .load ("docs/notrack/1" , Doc ).name = "v2"
926+ session .save_changes ()
927+
928+ with self .store .open_session () as session :
929+ self .assertEqual ("v1" , session .load ("docs/notrack/1" , Doc ).name )
930+
931+ with self .store .open_session () as session :
932+ self .assertEqual ("v2" , session .load ("docs/notrack/1" , Doc ).name )
933+
865934 def test_cache_context_does_not_affect_event_registration (self ):
866935 """Entering/exiting the cache context does not remove registered event handlers."""
867936 store = self .store
0 commit comments