Reputation: 6353
Does the ASP.NET SQL Profile Provider use caching? I mean if I pull data from the profile for a user will it hit the DB for each request?
I'm looking for a setting or any information on this. I had thought I read it would use cookies but I can't find this now.
Edit:
http://msdn.microsoft.com/en-us/library/aa478953.aspx describes process as
When called by SqlProfileProvider.GetPropertyValues, aspnet_Profile_GetProperties performs the following actions:
Upvotes: 3
Views: 1654
Reputation: 39807
From MSDN
When your application runs, ASP.NET creates a ProfileCommon class, which is a dynamically generated class that inherits the ProfileBase class. The dynamic ProfileCommon class includes properties created from the profile property definitions you specify in your application configuration. An instance of this dynamic ProfileCommon class is then set as the value of the Profile property of the current HttpContext and is available to pages in your application.
It appears that the Profile object is attached to the current HttpContext of the request. So, unless you create a new HttpContext, the profile data is loaded and stored here on first request.
EDIT - Allen brought up some good points for some clarification here -> the profile data is queried on each HttpRequest (e.g. when a new HttpContext is created). But within each request, calls to the profile provider for different properties do not keep hitting the DB, only on the first call.
Upvotes: 2
Reputation: 19446
The provider uses "caching" once per request that accesses the profile data. If you don't access profile data during any given request, it isn't queried. However, if you access profile data several times during one request (and don't update it) then its only queried once.
The important takeaway is this: if you access profile data on every request, then asp.net is querying the database once per request for your profile data!.
To specifically answer your question: "If I pull data from the profile for a user will it hit the DB for each [http] request?" Yes, it will hit the database each time.
You could probably build your own provider that does some form of session based caching so you're not always calling the database to lookup your users profile data. Here is a great article on the topic: Optimizing ASP.NET Profiles Performance
Upvotes: 1