When an object is updated by thread A, it is true that it is evicted from the L2 cache. However, if you have that object loaded in thread B, you are not seeing the new data immediately after the evict.
The objects in OpenAccess are refreshed in two ways and this behavior is valid disregarding if L2 cache is on or off.
- When a context calls SaveChanges() or ClearChanges(), all the objects that have been loaded by that context are put into a HOLLOW state. This means they will be refreshed next time they are accessed for read/write. The refreshed state is obtained from the L2 cache if the object has not been changed by another thread, otherwise it is fetched the database.
- If thread B knows about the objects that are changed by thread A(maybe you have some custom logic for that), you can explicitly call Refresh() on the objects that are being changed and get the latest data for them without calling SaveChanges() on the context in thread B.
And also, thanks a lot to Henrik for explaining the rest of the OpenAccess stack.
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward!
We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>