views:

428

answers:

3

We have data that's updated nightly in a database residing in the same instance as my app's database. So to save on database calls, I want to cache this static-for-the-day data into a List(Of MyObject). From a theory point of view, should this cached List(Of ) be cached in the presentation layer code, via a global variable? Should it be in a global variable in the .DLL?

I'm thinking in the .DLL, because I created a service layer, which is exposed publicly to the GUI and makes calls to the data access layer inside the .DLL:

Public Shared Function Search(ByVal criteria As Core.Other.Customer) As List(Of Core.Other.Customer)
    ' TODO: Check the customer cache to see if it has been populated yet. If not, populate it.
    If 1 = 1 Then
        ' TODO: Variable "list" needs to be a global object in the DLL.
        ' For SO readers: Dal class declared Friend.
        Dim list As List(Of Core.Other.Customer) = Dal.Search.Customers.GetCache()
    End If

    Dim results As New List(Of Core.Other.Customer)
    ' TODO: Find the relevant customers in the cache and add them to variable "results".
    Return results
End Function

Am I going about this the best way that I can?

A: 

You might consider doing it without caching and seeing if you have a performance/network issue. This might be premature optimazation?

matt eisenberg
Some users will use the application over VPN, which sadly to say is sub-par in the company. Database calls that take 2 seconds here take 10 seconds on VPN. I need to enter into this with some optimzation in mind.
HardCode
+2  A: 

Does your List(Of x) requires any processing or is it just raw data pulled from a database?

If it's just raw data pulled from a database it might be a good idea to cache it at the data access layer.

But if it required processing, then it should be done in the business logic layer

Since you're referring to presentational code and .DLL, did you happen to mean an n-tier architecture?

chakrit
The data is just raw, unprocessed data - a list of customers, their address, their ID, etc.Yes, it's n-tier.
HardCode
+2  A: 

I would tend to cache this in your service layer. I like to keep my data access simple (typically using an OR/M like NHibernate) so I don't want to do anything goofy there that might change my expectation of how the data access layer works (as a developer, I would expect all calls to the DAL to actually hit the DB, and not a cache, unless it was the OR'M's cache, and that's an implementation detail I don't care about).

The service seems like the appropriate place (and when I cache data, that is where I do it in my apps, if that helps at all).

Chris Holmes