thanks for your suggestion and answer. But I would like to know is there any difference between your and @slugster approach?
–
शेखरDec 28 '12 at 4:32

@krshekhar, as I said, above code wouldn't return null even if cache expiration time is zero (indicating that no caching is required). On side note, it eliminates an unnecessary cache look-up in cache-miss scenario but that really does not matter in scheme of things! Further, you can further re-factor above code to read the cache expiration time from config in static constructor but again...
–
VinayCDec 28 '12 at 5:07

Yes it is possible, if the cast as Collection<CProductMakesProps> fails then a null will be assigned to allMake, so this depends heavily on what you are returning from new CModelRestrictionLogic().GetTopMakes().

Based on the assumption that most cache and/or dictionary collections will allow you to check for the presense of a specific key, I would suggest a slightly more streamlined way of writing this:

if the cast as Collection<CProductMakesProps> fails then a null will be assigned to allMake true but after that the null check will assign value to the context.Cache am I right?
–
शेखरDec 27 '12 at 5:41

1

@krshekhar You have two different instances of the cast as Collection<CProductMakesProps> in your code, this will (silently) fail and return null if the type it is applied against cannot be cast that way. Your question was Is it possible that I get null value in the lobjprodMakeCol?, to which the answer is yes, it is possible with the way you have the code.
–
slugsterDec 27 '12 at 10:59