How to force a refresh of possibly cached value?

I have the following Repository:

Public Class PageRepository
    Private Shared _pages As BLL.PageCollection

    Shared Function AllPages() As BLL.PageCollection
        If _pages Is Nothing Then _pages = new BLL.PageCollection(LOADALL)
        Return _pages
    End Function
End Class

I do all selects using LINQ on the PageRepository.AllPages, and I also Add new entities through the collection using Repository.AllPages.AddNew().

When I call Repository.AllPages.Save() the data is stored in the database, however the _pages private shared variable is maintained.

Should I somehow force a refresh of this variable everytime a page is updated? Or should this be done through a Module / Static class and is my implementation wrong?

Answers


When you're performing the save, you are invalidating the cache. You should force a refresh at that point or somehow expire the cache to any consumers. That depends how it's being consumed and how you designed your architecture.

Are you sure that caching is actually needed? SQL Server (and other DBs) have nice caching features and the LINQ dataContext for LINQ to SQL and Entity Framework have additional features that may be utilized. In short, have you tried using

Public Class PageRepository

    Shared Function AllPages() As BLL.PageCollection
        Return new BLL.PageCollection(LOADALL)
    End Function

End Class

If you have and you do need the caching, can you push the caching to the BLL?


Need Your Help

Inspection of Structs in Swift during debug doesn't work

xcode swift struct xcode7 lldb

Debugging running a unit test in Swift 2.1 / Xcode 7, this struct is defined -

How to find whether the MORE FRAGMENTS field is set or no?

c network-programming header protocols packet-sniffers

Given this header , how do I find if the MORE FRAGMENTS field is set or not..