Skip to content

[Question] MemoryCache with cloned objects on Get, atomic update of cache #262

Description

@kzkzg

Hi,

  1. I'm using default IMemoryCache, which keeps reference to object, so when i get value from cache and change something with it, this change apply to whole cache. Is it possible that memorycache return deepcloned objects on Get? I guess solution could be to pass custom implementation of IMemoryCache which deepclone objects on read. Do you know some other implementations of IMemoryCachen which can be used to achive that? Or mayby there is other way to do that?

  2. I have simple code, get from cache, update value, and Set to cache again, everything is in Redis Redlock block

using var redLock = await LockHelper.AquireLockAsync(key)...
var result = await _fusionCache.TryGetAsync....
result = ProcessResult(result)...
await _fusionCache.SetAsync(key, result...

is it better way to do that? Mayby some specialized method which could be used like this:

_fusionCache.UpateAsync(key, ProccessResult)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions