I have a method that will expire null items immediately, however I wanted to know if there w as better way to do this for all memory cache items instead of repeating the same code over and over
output = _cache.GetOrAdd("GetRecordUri" + 123, entry =>
{
var record = internalGetRecordUri();
if (record == null)
// expire immediately
entry.AbsoluteExpirationRelativeToNow = new TimeSpan(-1, 0, 0, 0);
else
entry.AbsoluteExpirationRelativeToNow = new TimeSpan(1, 0, 0, 0);
return record;
});
The code in bold seems redundant Is there an extension that I can use that will do the same?
You can place this check in separate method:
And call it everywhere you need: