为了加快速度,我正在考虑对我的表实现时间戳类型方法,以限制我的查询只返回已更改的行.
然后我打算将这个较小的数据集与我的缓存数据表合并.
有没有人做过类似的事情,或者有什么东西可以解决这个问题吗?
如果我直接潜入,我觉得这可能会重新发明车轮状况.
解决方法
或者,我建议使用SqlCacheDependency类,它可以为您保持最新的缓存.我不能评论任何现实世界的优点,或性能比较与时间戳方法,因为我自己没有使用它.
还有一篇关于sqlCacheDependency here的有用文章
更新:
是的,我认为它不会真正刷新数据.听起来你必须自己做.
从第二个链接:
When the data changes—and only
then—the cache items based on that
data are invalidated and removed from
the cache. The next time you request
that item from the cache,if it is not
in the cache,you can re-add the
updated version to the cache and be
assured that you have the latest data
sql Server 2005 monitors changes to
the result set of a particular sql
command. If a change occurs in the
database that would modify the results
set of that command,the dependency
causes the cached item to be
invalidated. This allows sql Server
2005 to provide row-level
notification.
我个人认为我会采用时间戳方法(这是我以前做过的),因为我无法从中看到sqlCacheDependency会带来任何性能上的好处 – 我认为它会降低性能(只是更容易)实行).有一天,我会试着尝试使用sqlCacheDependency进行正确的性能分析:)
更新2:
关于将新数据合并到现有数据表中,我认为数据表的Merge方法是您想要的.
The Merge method is used to merge two DataTable objects that have largely similar schemas. A merge is typically used on a client application to incorporate the latest changes from a data source into an existing DataTable.
…
…
When merging a new source DataTable into the target,any source rows with a DaTarowState value of Unchanged,Modified,or Deleted,is matched to target rows with the same primary key values. Source rows with a DaTarowState value of Added are matched to new target rows with the same primary key values as the new source rows.
您只需确保在数据表上定义作为主键的列.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。