开发者

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 imple开发者_JAVA技巧mentation wrong?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜