-
Notifications
You must be signed in to change notification settings - Fork 160
Description
Describe the bug
When objects fetched from the cache with Auto Clone enabled are placed into a list and then modified, subsequent requests to the cache return the modified object.
For example: if several objects are all stored individually by ID number, when you return several of them and place them in a list - modifying the objects after they are placed in the list causes the cache object to change rather than having no effect because Auto Clone was enabled.
To Reproduce
Here's a MRE (Minimal Reproducible Example) of the issue:
https://github.com/nlconor/FusionCache-AutoCloneRepro
The /single
endpoint shows Auto Clone working correctly when not using a list (as in the docs example).
The /list
endpoint shows my difficulties when using cached objects inside lists.
The example works something like this:
- Tries to fetch 3 objects from the cache
- If one or more is missing then it populates the cache with 3 new objects
- For each of the "result items" (which either came from the cache or were generated this run), changes a property inside them
- Returns the changed property to the user.
The first run works as expected but if you break on line 90 on the second run and inspect the contents ofresults
, you will see each of the objects in the list has theUser
property set.
Expected behavior
When fetching objects from the cache with EnableAutoClone
set, modifying the returned objects should not afffect future instances of that object - even if the objects are placed into a list.
Relating to the example - I expect that when running the /list
endpoint a second time, the User
property should be null on like 90 (instead of being populated by the previous run's actions).
Versions
I've encountered this issue on:
- FusionCache version 2.1.0
- .NET version 9.0.203
- OS version Mac OS 15.3.2
Thanks for all your efforts on this great library so far!