代码之家  ›  专栏  ›  技术社区  ›  HardCode

WinForms应用程序数据缓存-缓存在哪一层?

  •  1
  • HardCode  · 技术社区  · 16 年前

    我们的数据每晚都会在与我的应用程序数据库位于同一实例中的数据库中更新。因此,为了节省数据库调用,我想将这个静态的当日数据缓存到List(Of MyObject)中。从理论角度来看,这个缓存的List(of)是否应该通过全局变量缓存在表示层代码中?它是否应该在中的全局变量中。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
    

    这是我能做到的最好的方式吗?

    3 回复  |  直到 16 年前
        1
  •  3
  •   Chris Holmes    16 年前

    我倾向于将其缓存在您的服务层中。我喜欢保持数据访问的简单性(通常使用像NHibernate这样的OR/M),所以我不想在那里做任何愚蠢的事情,这可能会改变我对数据访问层工作方式的期望(作为一名开发人员,我希望所有对DAL的调用都能真正到达数据库,而不是缓存,除非它是OR'M的缓存,这是我不关心的实现细节)。

    该服务似乎是合适的地方(当我缓存数据时,如果这有帮助的话,那就是我在应用程序中缓存数据的地方)。

        2
  •  2
  •   chakrit Dutchie432    16 年前

    你的List(Of x)需要任何处理,还是只是从数据库中提取的原始数据?

    但如果它需要处理,那么它应该在业务逻辑层中完成

    因为你指的是表示性代码和。DLL,你是说 n-tier architecture ?

        3
  •  0
  •   matt eisenberg    16 年前

    您可以考虑在不缓存的情况下执行此操作,并查看是否存在性能/网络问题。这可能是过早的优化?