alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

Copying the cached Item #90

Closed IamChandanKumar closed 4 years ago

IamChandanKumar commented 5 years ago

I want to copy one of the cached data into the cache itself with different key.

Is it possible to achieve directly into the cache or do we need to first get the cached data and then create another Cached item with another key?

alastairtree commented 4 years ago

In memory caching is based on object references so if you were to put the same object into the cache with two different keys you would have two references to the same object. If you want to copy the object you would be best to make the object cloneable and then clone the object in the cache, and cache the clone with a second cache key. Hope that helps.