MemoryCache cache = MemoryCache.Default; string key = "myKey"; string value = "Hello world!"; cache.AddOrUpdate(key, value, (k, v) => v);
cache.AddOrUpdate(key, "new value", (k, v) => "updated value");In this example, we're updating the value of an existing cache item with the specified key. The lambda expression passed as the third parameter to AddOrUpdate determines the new value of the cache item. The Cache AddOrUpdate method is part of the .NET Framework and is available in the System.Runtime.Caching.dll assembly.