RDBC-1035 RDBC-1036 Add aggressive caching context managers and store-level session events#277
Open
redknightlois wants to merge 1 commit intoravendb:v7.2from
Open
RDBC-1035 RDBC-1036 Add aggressive caching context managers and store-level session events#277redknightlois wants to merge 1 commit intoravendb:v7.2from
redknightlois wants to merge 1 commit intoravendb:v7.2from
Conversation
2d83c6c to
b59cf08
Compare
Contributor
|
please bump PR to run checks |
b59cf08 to
6e4f178
Compare
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py
Outdated
Show resolved
Hide resolved
poissoncorp
reviewed
Apr 10, 2026
poissoncorp
reviewed
Apr 10, 2026
| # build an eviction object, but only one will be stored; the loser is | ||
| # discarded via close(). | ||
| eviction = DocumentStore._AggressiveCacheEviction(self, database) | ||
| with self.__add_change_lock: |
Contributor
There was a problem hiding this comment.
let's replace the giant comment above with "this lock is here to achieve ConcurrentDict-like behavior" - will increase readability by far
poissoncorp
reviewed
Apr 10, 2026
poissoncorp
reviewed
Apr 10, 2026
Member
Author
|
Let me run the cross gap analysis workflow again. This used a much older version (the first draft). |
6e4f178 to
3879ceb
Compare
poissoncorp
reviewed
Apr 10, 2026
3879ceb to
fc03aba
Compare
poissoncorp
reviewed
Apr 10, 2026
| event() | ||
|
|
||
| # todo: evict items from cache based on changes | ||
| for eviction in list(self.__aggressive_cache_changes.values()): |
Contributor
There was a problem hiding this comment.
should also change var name here when the class name is improved
poissoncorp
requested changes
Apr 10, 2026
72c7a7d to
6ce68fb
Compare
poissoncorp
reviewed
Apr 10, 2026
poissoncorp
reviewed
Apr 10, 2026
|
|
||
| # --- aggressive cache --- | ||
|
|
||
| def test_get_from_cache_returns_empty_release_cache_item_for_non_cacheable_command(self): |
Contributor
There was a problem hiding this comment.
can we add happy-path tests proving aggressive cache works? if it's there, correct me please - there's a lot of tests that cover different corner cases
…evel events - Add add/remove_before_store, add/remove_after_save_changes, add/remove_before_delete, add/remove_before_query to DocumentStoreBase; register_events_for_session wires them into every new session - Add aggressively_cache_for(duration, mode) and disable_aggressive_caching() context managers on DocumentStore; AggressiveCacheOptions is thread-local via threading.local(), mirroring C# AsyncLocal<T> - Add _AggressiveCacheEviction inner class: subscribes to Changes() feed and increments HttpCache.generation on DocumentChange / IndexChange events - Fix _listen_to_changes_and_update_cache: construct _AggressiveCacheEviction outside __add_change_lock to prevent deadlock when store.changes() (which acquires the same lock) is called during construction - Remove dead HttpCache.ReleaseCacheItem inner class; fix _get_from_cache to import and return the module-level ReleaseCacheItem for non-cacheable command paths (was AttributeError at runtime) - Fix before_delete event timing for key-based session.delete(): move BeforeDeleteEventArgs dispatch from delete() into prepare_for_save_changes() via __prepare_for_key_deletes, matching C# PrepareForEntitiesDeletion timing and making both delete paths (key vs entity) consistent - Fix session-level remove_before_query: was appending instead of removing, making it impossible to unregister a query event handler on an open session - Rename session-level remove_before_delete_entity to remove_before_delete, matching the naming convention of all other remove methods and the store-level API - Add no_caching guard to _check_aggressive_cache_guard test helper so it exactly mirrors the condition in execute(); add test for no_caching bypass - Add integration tests verifying event args contents: args.entity identity in OnBeforeStore and args.key in OnBeforeDelete (per C# Events.cs spec) - Remove test for unreachable RAW-command cache-hit path: _get_from_cache never returns a populated item for non-OBJECT commands, so the scenario the test described could not occur in production
6ce68fb to
6df930d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue link
https://issues.hibernatingrhinos.com/issue/RDBC-1035
https://issues.hibernatingrhinos.com/issue/RDBC-1036
Additional description
RDBC-1035 – Adds aggressive caching support to the Python client.
store.aggressively_cache_for(duration)andstore.disable_aggressive_caching()are context managers that enable/disable serving GET responses directly from the local HTTP cache without a server round-trip. Cache options are thread-local, matching the C#AsyncLocal<T>semantics. The cache is automatically invalidated when document or index change notifications arrive.RDBC-1036 – Adds store-level session event hooks:
add_before_store,add_after_save_changes,add_before_delete, andadd_before_query(with correspondingremove_*variants). Handlers registered on the store are automatically wired into every new session, eliminating the need to re-register on eachopen_sessioncall.Type of change
How risky is the change?
Backward compatibility
Is it platform specific issue?
Documentation update
Documentation Requiredtag.Testing by Contributor
private)Testing by RavenDB QA team
QA Requiredtag.Is there any existing behavior change of other features due to this change?
UI work
Studio Requiredtag.