in sane world, have expected updatecallback
property increment collection of arguments. doesn't: in final line of test, updatearguments
collection expected 3 (twice each set
call , once remove
call), empty.
the test rough , ready, should enough illustrate odd happening.
or missing obvious.
edit: getting stranger. based on question memorycache updatecallback not working, says thread.sleep
blocks memorycache.default
object, changed original thread.sleep(5000)
call task.factory.startnew(() => thread.sleep(10000)).wait();
. then, if comment out call memorycache.default.remove()
, updatearguments
collection indeed incremented, once, , when "personkey"
cached item expires. 2 set()
, 1 remove()
calls ignored completely. i'm having "what heck" moment.
[test] public void thememorycachemaintainsamemberandinvokestheupdatecallback() { var person = new person { givenname = "rob", lastname = "lyndon"}; var givenname = person.givenname; var lastname = person.lastname; var updatearguments = new list<cacheentryupdatearguments>(); memorycache.default.set("personkey", person, createnewpolicy(updatearguments)); var cacheditem = memorycache.default.get("personkey") 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") person; assert.isnotnull(cacheditem); assert.that(cacheditem.givenname, is.equalto(givenname)); assert.that(cacheditem.lastname, is.equalto(lastname + " - updated")); task.factory.startnew(() => thread.sleep(10000)).wait(); thread.sleep(5000); assert.that(updatearguments.count, is.equalto(3)); } private static cacheitempolicy createnewpolicy(icollection<cacheentryupdatearguments> updatearguments) { return new cacheitempolicy { absoluteexpiration = datetimeoffset.now.addseconds(1), updatecallback = args => updatearguments.add(args) }; }
Comments
Post a Comment