Note that there are some explanatory texts on larger screens.

plurals
  1. POMemoryCache: Why is this integration test failing? UpdateCallBack looks like it's broken
    primarykey
    data
    text
    <p>In a sane world, I would have expected the <code>UpdateCallBack</code> property to increment my collection of arguments. But it doesn't: in the final line of this test, the <code>updateArguments</code> collection is expected to be 3 (twice for each <code>Set</code> call and once for the <code>Remove</code> call), but it is empty.</p> <p>The test is rough and ready, but it should be enough to illustrate that something odd is happening.</p> <p>Or that I am missing something obvious.</p> <p>EDIT: This is getting stranger. Based on the question <a href="https://stackoverflow.com/questions/9650614/memorycache-updatecallback-not-working">MemoryCache UpdateCallback not working</a>, which says that <code>Thread.Sleep</code> blocks the <code>MemoryCache.Default</code> object, I changed the original <code>Thread.Sleep(5000)</code> call to <code>Task.Factory.StartNew(() =&gt; Thread.Sleep(10000)).Wait();</code>. Then, if I comment out the call to <code>MemoryCache.Default.Remove()</code>, the <code>updateArguments</code> collection does indeed get incremented, but only once, and that is when the <code>"PersonKey"</code> cached item expires. The two <code>Set()</code> and one <code>Remove()</code> calls are ignored completely. I'm having a "What the heck" moment.</p> <pre><code>[Test] public void TheMemoryCacheMaintainsAMemberAndInvokesTheUpdateCallback() { var person = new Person { GivenName = "Rob", LastName = "Lyndon"}; var givenName = person.GivenName; var lastName = person.LastName; var updateArguments = new List&lt;CacheEntryUpdateArguments&gt;(); MemoryCache.Default.Set("PersonKey", person, CreateNewPolicy(updateArguments)); var cachedItem = MemoryCache.Default.Get("PersonKey") as Person; Assert.IsNotNull(cachedItem); Assert.That(cachedItem.GivenName, Is.EqualTo(givenName)); Assert.That(cachedItem.LastName, Is.EqualTo(lastName)); person.LastName = "Lyndon - Updated"; MemoryCache.Default.Set("PersonKey", member, CreateNewPolicy(updateArguments)); cachedItem = MemoryCache.Default.Get("PersonKey") as Person; Assert.IsNotNull(cachedItem); Assert.That(cachedItem.GivenName, Is.EqualTo(givenName)); Assert.That(cachedItem.LastName, Is.EqualTo(lastName + " - Updated")); Task.Factory.StartNew(() =&gt; Thread.Sleep(10000)).Wait(); Thread.Sleep(5000); Assert.That(updateArguments.Count, Is.EqualTo(3)); } private static CacheItemPolicy CreateNewPolicy(ICollection&lt;CacheEntryUpdateArguments&gt; updateArguments) { return new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(1), UpdateCallback = args =&gt; updateArguments.Add(args) }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload