Skip to content

Cached item returned from MemoryCache seems to mutate MemoryCache instance when modified. #145

Answered by jodydonetti
rlightner asked this question in Q&A
Discussion options

You must be logged in to vote

The only solution is to do some sort of "deep clone", in theory.

But if you try to do that you'll see pretty quickly that there are a lot of "ifs" (serializability and friends) and "buts" (cycles) and in general various things to consider, including - but not limited to - performance considerations.

Because of this, it is not something that in general is done natively inside of caching solutions, including FusionCache.

I would suggest you to consider objects received from the cache not to be modifiable, and clone them yourselves only if and when needed.

You can find various solutions online on how to do deep clones in C# (with various limitations and perf considerations).

Let me know if t…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@rlightner
Comment options

@jodydonetti
Comment options

Answer selected by rlightner
@rlightner
Comment options

@rlightner
Comment options

@jodydonetti
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants