如何强制刷新可能缓存的值?
我有以下存储库:
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
我在 PageRepository.AllPages
上使用 LINQ 进行所有选择,并且还使用 Repository.AllPages.AddNew()
通过集合添加新实体。
当我调用 Repository.AllPages.Save() 时,数据存储在数据库中,但保留了 _pages 私有共享变量。
每次更新页面时我是否应该以某种方式强制刷新此变量?或者应该通过 Module
/ Static class
来完成,我的实现是否错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您执行保存时,您将使缓存失效。您应该在此时强制刷新,或者以某种方式使任何消费者的缓存过期。这取决于它的使用方式以及您如何设计架构。
您确定确实需要缓存吗? SQL Server(和其他数据库)具有良好的缓存功能,并且 LINQ to SQL 的 LINQ dataContext 和实体框架具有可以利用的其他功能。简而言之,您是否尝试过使用
如果您有并且确实需要缓存,您可以将缓存推送到BLL吗?
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
If you have and you do need the caching, can you push the caching to the BLL?