Thursday, 15 August 2013

Implications of caching objects (per user) and garbage collection

Implications of caching objects (per user) and garbage collection

When you store something in ASP.NET's build in cache, how does this work
with the garbage collector?
Example:
if( not in cache)
{
List<UserSales> sales = SalesService.GetByUserId(loggedInUser.id);
InsertToCache(cacheKey, sales);
}
else
{
// loads from cache
}
So for each user, I first check if the data is in cache.
What I want to know is, what effect does this have on the garbage
collector? If the sales object has say 200-500 rows for some users, how
will the GC behave in this situation?
What if I have a sliding expiration for 20 minutes so it is removed from
the cache, just because it is removed, it still has to be GC'd correct?
The only thing holding a reference to sales would be the cache system, and
the mvc view page but that goes out of scope when the requests ends.

No comments:

Post a Comment