OutputCaching per user per culture, memory performance
I'm developing a website in which every type of user ({guest,loggedIn}) may view [N] pages, in different cultures ({en-US...}). I'm using GetVaryByCustomString to process caching for each page:
Public Overrides Function GetVaryByCustomString(ByVal currentContext As HTTPContext, ByVal开发者_如何学Go customArgs As String) As String
Select Case customArgs
Case "userAndCulture"
Return String.Format("{0}{1}", Languages.getLanguageID(), User.getUserID(0))
End Select
Return MyBase.GetVaryByCustomString(currentContext, customArgs)
End Function
Note: getUserID() has a default "returnValueWhenNull" of DBNull.Value (it's used for SQL for most of the work) so i'm sending 0 (zero) so all guests will have the same page.
However, my main question is: such mechanism won't kill the server in terms of memory? I mean, aren't there potential [loggedInUsersCount] * [culturesCount] * [pagesCount] pages?
One more note: pages are cached in server memory only
It won't kill the server because the cache has a finite limit. It won't exceed a certain boundary. ASP.NET manages the cache size pragmatically. When there's memory scarcity, it will flush least used items from the cache. So, you are safe.
But putting so many items on cache means you aren't giving other data much chance to remain on cache. You should look at the windows performance counter and check the ASP.NET OutputCache hit ratio to see whether you are really getting good hit on the output cache.
精彩评论