缓存 SQL 查询数据的技术

发布于 2024-07-09 22:57:03 字数 991 浏览 8 评论 0原文

阅读了有关此主题的一些内容:

缓存 MySQL 查询

http://www.danga.com/memcached/

我的 SQL 缓存问题: http://www.petefreitag.com/item/390.cfm

http://framework.zend.com/manual/en/zend .cache.html#zend.cache.introduction

我有一组非常独特(狭窄)的查询,我认为我可以在我当前的 FastCGI C API 可执行文件(不是 PHP)中很容易地实现一些缓存。

Zend 将他们的框架描述为: 缓存记录通过后端适配器(File、Sqlite、Memcache...)通过灵活的 ID 和标签系统进行存储。

这是如何实施的?

由于如果表已更改,相同的查询可能会返回不同的结果,因此我不仅需要监视查询,还需要监视 UPDATE、INSERT 和 DELETE(目前为 MySQL),因为这仅发生在我的一个进程中,所以我可以轻松添加一个当表发生更改时删除缓存的语句。

客户端只允许 SELECT,在这种情况下,我可以对查询进行哈希处理,并将它们与指向包含结果的文件的指针一起存储在哈希表或 btree 索引中。

有没有更好的办法?

Having read some on this subject:

Caching MySQL queries

http://www.danga.com/memcached/

My SQL Caching problem:
http://www.petefreitag.com/item/390.cfm

http://framework.zend.com/manual/en/zend.cache.html#zend.cache.introduction

I have a very unique (narrow) set of Queries and I think I could implement some caching quite easily within my current FastCGI C API executables (NOT PHP).

Zend describes their framework as:
cache records are stored through backend adapters (File, Sqlite, Memcache...) through a flexible system of IDs and tags.

HOW is this implemented?

Since the same query can return different results if the Table has been changed, I need to monitor not only Queries, but UPDATE, INSERT and DELETE also (MySQL for now) Since this only happens from one of my processes, I could easily add a statement that deletes the cache when a table change is made.

Only SELECTs are permitted by the clients, in which case I could hash the queries and store them in a hash table or btree index along with a pointer to the file containing the results.

Is there a better way?

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

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

发布评论

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

评论(3

雨的味道风的声音 2024-07-16 22:57:03

噢,伙计,这是个好问题。
作为一名 .NET 开发人员,我很幸运在过去 7 年里完全不用担心这个问题。 我不必担心,因为.NET 实现了非常强大的缓存机制来完成您想做的事情。

有没有办法在中间层或表示层做到这一点?

Oh man, that is a good question.
Being a .NET developer, I have been fortunate enough to not have to worry about this at all over the last 7 years. I don't have to worry because .NET implements a quite powerful caching mechanism to do what you want to do.

There is no way to do this at a middle tier or presentation tier layer?

习ぎ惯性依靠 2024-07-16 22:57:03

.NET 对于快速开发来说确实很方便,但它也带来了一些不良后果,因为 MS 成了聋子的同床异梦!

我也更喜欢开发自己的解决方案,因为我可以根据我的需求定制它们。 我不需要太多的复杂性,只需要一些将入站查询与服务器端结果集联系起来的机制。 该演示文稿在存在单独数据库的客户端上进行。 请求实际上只是为了更新客户端数据库,因此为了回答您的问题,客户端缓存已全部实现。

.NET is certainly convenient for fast development but it has some undesirable consequences as MS makes a deaf bedfellow!

I also prefer to develop me own solutions as I can tailor them to my needs. I don't need a lot fo sophistication, just some mechanism to tie inbound queries to results sets on the server side. The presentation is don on the client side where a seperate database exists. Requests are really only to update the client side database so in answer to your question, the client side caching is allready implemented.

秋心╮凉 2024-07-16 22:57:03

当我想到这一点时,我意识到虽然将结果缓存到磁盘更快,但磁盘上的负载会显着增加。 就我而言,数据库的查询速度并不慢,最大的问题是结果集所需的内存,每个结果集最多 3MB。 如果我在 xfer 继续时将其全部保留在 mempry 中,这将立即耗尽服务器内存

As I think about this, I realize that allthough Caching results to disk is faster, the load on the disk will increase significantly. In my case the DB is not that slow for queries, it is the memory required for the result set that is the biggest issue, up to 3MB per result set. This will eat up server memory in no time If I keep it all in mempry while the xfer proceeds

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