I have an ASP.net site that is essentially just a user interface for a class library I created. Each of the classes in this class library contain a static definition class with static references to compiled queries.
我有一个ASP.net站点,它基本上只是我创建的类库的用户界面。此类库中的每个类都包含一个静态定义类,其中包含对已编译查询的静态引用。
Like so:
class MyRecord
{
/*Some Properties,Fields, and Methods*/
internal static class Queries
{
public static Func<MyDataContext, MyRecord> ACompiledQuery =
CompiledQuery.Compile<MyDataContext, MyRecord>(
(MyDataContext db) =>
from mr in db.MyRecords
select mr);
}
}
Given this structure and given that each web page references this library, I have a couple questions
鉴于这种结构,并且鉴于每个网页都引用了这个库,我有几个问题
Question 1: Every request to an IIS web server essentially starts a new thread, correct?
问题1:对IIS Web服务器的每个请求基本上都会启动一个新线程,对吗?
Question 2: If so, does this mean that for every request I end up recompiling these queries?
问题2:如果是这样,这是否意味着对于每个请求我最终都会重新编译这些查询?
Question 3: Is there anyway to reduce the amount of times I recompile these queries?
问题3:无论如何减少重新编译这些查询的次数?
2 个解决方案
#1
Static items are shared across threads within the same AppDomain, and so you will no re-compile the query for each request.
静态项在同一AppDomain中的线程之间共享,因此您不会为每个请求重新编译查询。
#2
Question 1: Every request to an IIS Web server is handled by an existing thread from the application's threadpool
问题1:对IIS Web服务器的每个请求都由应用程序的线程池中的现有线程处理
Question 2: Already answered by Joel
问题2:Joel已经回答了问题
Question 3: It is Static so is only either created (or compiled) once when the application is started
问题3:它是静态的,因此只在应用程序启动时创建(或编译)一次
#1
Static items are shared across threads within the same AppDomain, and so you will no re-compile the query for each request.
静态项在同一AppDomain中的线程之间共享,因此您不会为每个请求重新编译查询。
#2
Question 1: Every request to an IIS Web server is handled by an existing thread from the application's threadpool
问题1:对IIS Web服务器的每个请求都由应用程序的线程池中的现有线程处理
Question 2: Already answered by Joel
问题2:Joel已经回答了问题
Question 3: It is Static so is only either created (or compiled) once when the application is started
问题3:它是静态的,因此只在应用程序启动时创建(或编译)一次