ASP.NET Profile Data Cached?

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:

  1. Queries the aspnet_Applications table to convert the application name input to it into an application ID.
  2. Queries the aspnet_Users table to convert the user name input to it into a user ID.
  3. Queries the aspnet_Profile table for the PropertyNames, PropertyValuesString, and PropertyValuesBinary fields for the specified user.
  4. Updates the user's last activity date in the aspnet_Users table with the current date and time.

Answers


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.


Yes and no

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


Need Your Help

Backup & recovery of multiple MySQL databases (InnoDB & MyISAM)

mysql database backup database-backups

I am working on nightly and hourly backups of MySQL Databases. There are multiple MySQL databases which are either InnoDB or MyISAM (Note: Each database is either InnoDB or MyISAM for a reason). Wi...

How to iterate through a Component's Children in Typescript React?

reactjs typescript react-jsx tsx

How do I iterate through a React component's children in Typescript tsx?