You are implementing an ASP.NET application that includes the following requirements. Retrieve the
number of active bugs from the cache, if the number is present. If the number is not found in the
cache, call a method named GetActiveBugs, and save the result under the ActiveBugs cache key.
Ensure that cached data expires after 30 seconds. You need to add code to fulfill the requirements.
Which code segment should you add?
A.
Dim numOfActiveBugs As Integer? = DirectCast(Cache(“ActiveBugs”), Integer?)
If Not numOfActiveBugs.HasValue Then
Dim result As Int32 = GetActiveBugs()
Cache.Insert(“ActiveBugs”, result, Nothing, DateTime.Now.AddSeconds(30),
Cache.NoSlidingExpiration)
numOfActiveBugs = result
End If
ActiveBugs = numOfActiveBugs.Value
B.
Dim numOfActiveBugs As Integer = CInt(Cache.Get(“ActiveBugs”))
If numOfActiveBugs <> 0 Then
Dim result As Integer = GetActiveBugs()
Cache.Insert(“ActiveBugs”, result, Nothing,
DateTime.Now.AddSeconds(30), Cache.NoSlidingExpiration)
numOfActiveBugs = result
End If
ActiveBugs = numOfActiveBugs
C.
Dim numOfActiveBugs As Integer = 0
If Cache(“ActiveBugs”) Is Nothing Then
Dim result As Integer = GetActiveBugs()
Cache.Add(“ActiveBugs”, result, Nothing, DateTime.Now.AddSeconds(30),
Cache.NoSlidingExpiration,
CacheItemPriority.Normal, Nothing)
numOfActiveBugs = result
End If
ActiveBugs = numOfActiveBugs
D.
Dim numOfActiveBugs? As Integer =
DirectCast(Cache(“ActiveBugs”), Integer?)
If Not numOfActiveBugs.HasValue Then
Dim result As Integer = GetActiveBugs()
Cache.Insert(“ActiveBugs”, result, Nothing, Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(30))
numOfActiveBugs = result
End If
ActiveBugs = numOfActiveBugs.Value
The Answer is A.
http://www.aiotestking.com/microsoft/which-code-segment-should-you-add-24/
(Convert from C# to VB