I have a function which calculates distance from database records. This function is called at least twice in one asp.net page request. In this time period the result does not change. So what to do to cache result, I need performance in my app.
For example:
public static int GetKilometers(int VehicleID)
{ /*some db query and calculations*/ }
If you’re only concerned about the result in the lifetime of one page request (as you mention in your question), a simple local variable will suffice:
This would prevent any memory concerns from excessive caching, but still allow some efficiency by not calculating the data twice for the same request.
One note is that you probably don’t want this static, as that will cache the result across multiple users of your application.