You will have to forgive this question as I am not experienced with multi-threading. I have been using the caching pattern outlined in the VB 2005 book on pages 405, 453, and 454. I am confused as to why the code in the GetList and InvalidateCache methods are not within Synclock blocks. I can see how this would not be an issue on the client side, but on the server side couldn't multiple threads (ie server side data portals) be trying to call these methods at the same time?
Thanks,
jk
I have been experimenting with the Enterprise Library Caching Application Block and I am considering using this for caching. My code for the GetList and InvalidateCache methods would look something like this:
Public Shared Function GetList() As NameValueList
Dim cm As CacheManager = CacheFactory.GetCacheManager
Dim mList As NameValueList
mList = DirectCast(cm.GetData("Key"), NameValueList)
If mList Is Nothing Then
mList = DataPortal.Fetch(Of NameValueList)(New Criteria)
cm.Add("Key", mList)
End If
Return mList
End Function
Public Shared Sub InvalidateCache()
Dim cm As CacheManager = CacheFactory.GetCacheManager
cm.Remove("Key")
End Sub
Since the CacheManager is itself thread-safe (according to the Enterprise Library documentation), then there is no need for Synclock blocks in these methods, correct?
OK, great. Thanks for your help.
jk
For the most part, caching will occur on the client side. However, we have some objects with business rules which require look ups in read-only collections. Since we check business rules in DataPortal_Create and DataPortal_Fetch calls, these read-only collections will be loaded and cached on the server side.
Copyright (c) Marimer LLC