直写式缓存

发布于 2024-08-26 17:25:19 字数 173 浏览 3 评论 0原文

我正在尝试执行直写式缓存的 C# 实现,以最大程度地减少对数据库的读取命中,我需要您的建议、文章或示例代码来完成此任务。

最初,这仅在一台服务器上使用,但将更新为在集群环境中工作。

我只能在 Oracle 网站上找到一篇值得一读的文章。

请分享您的看法

问候 穆巴沙尔

I am trying to do an C# implementation of Write-through Cache to minimize the read hits on db i need your suggestions, articles or sample codes to fulfill this assignment.

Initially this would be use only on one server but will be updated to work in clustered environment.

I only able to get a worth reading article on Oracle Site.

Please share your views

Regards
Mubashar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-09-02 17:25:19

最简单的做法是在比数据库连接级别更高的级别进行缓存。如果您有一个数据访问层,可以将您从 SQL 的细节中封装出来,那么这通常是一个好地方。如果你有一个请求数据对象的地方,那就更好了;您的缓存密钥可以是这些对象的标识。

您最终可能想要的是一个缓存代理,它封装您的缓存逻辑,阻止读取,但将写入传递到底层服务(对象持久层或数据访问层)。您可以使用WeakReference 使未使用的对象从缓存集合中过期,在这种情况下,您只需要进行一些清理即可。另一方面,您可以编写自己的过期逻辑,在这种情况下,您必须进行更多清理,但会保留更多控制权。

由于没有更具体的细节,很难给你具体的答案。

The easiest thing to do would be to cache at a higher level than the database-connectivity level. If you have a data access layer that encapsulates you from the nitty-gritties of SQL, that's usually a good place. If you have a place where data objects are requested, that would be even better; your caching key can be the identity of those objects.

What you ultimately will probably want is a caching Proxy which encapsulates your caching logic, interdicting reads but passing writes through to the underlying service (the object persistence layer or the data access layer). You can use WeakReference to cause unused objects to expire out of your caching collection, in which case you'll need to do just a little bit of clean up. On the other hand you can write your own expiration logic, in which case you have to do more clean up but will retain more control.

Without more specific details, it's hard to give you a specific answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文