is there a difference in performance when making properties static/shared that were instance properties before, maybe any locking mechanisms?
There is a heavily used object in HttpCache which was accessible through a property in a page-instance(Service.aspx). Now i wonder if it would be better to make it static because the HttpCache is shared across the application anyway.
The main reason i decided to make it static was because it is simpler to reference(Service.dsRMA
vs. ((Service)Page).dsRMA
).
I'm aware of the problems that can occur regarding static functions and thread safety.
Thank you for your time.
Before:
C#
public ERPModel.dsRMA dsRMA {
get {
if (Cache("DS_RMA") == null) {
Cache("DS_RMA") = new ERPModel.dsRMA();
}
return (ERPModel.dsRMA)Cache("DS_RMA");
}
}
VB
Public ReadOnly Property dsRMA() As ERPModel.dsRMA
Get
If Cache("DS_RMA") Is Nothing Then
Cache("DS_RMA") = New ERPModel.dsRMA
End If
Return DirectCast(Cache("DS_RMA"), ERPModel.dsRMA)
End Get
End Property
After:
C#
public static ERPModel.dsRMA dsRMA {
get {
if (HttpContext.Current.Cache("DS_RMA") == null) {
HttpContext.Current.Cache("DS_RMA") = new ERPModel.dsRMA();
}
return (ERPModel.dsRMA)HttpContext.Current.Cache("DS_RMA");
}
}
VB
Public Shared ReadOnly Property dsRMA() As ERPModel.dsRMA
Get
If HttpContext.Current.Cache("DS_RMA") Is Nothing Then
HttpContext.Current.Cache("DS_RMA") = New ERPModel.dsRMA
End If
Return DirectCast(HttpContext.Current.Cache("DS_RMA"), ERPModel.dsRMA)
End Get
End Property