Kohana 3 - 如何使用memcached缓存查询结果?
我正在使用 Kohana 3 框架进行一个大型项目,实际上我需要改进它,添加缓存系统以减少 MySQL 连接数量。
我正在考虑开发一个基本(但通用)模块来生成完整的查询结果缓存,但将表查询结果单独管理到不同的组中。
Pex:
缓存组:users、roles、roles_users等。
每个组包含对应表的所有查询结果。因此,如果我想从“users”获取值,缓存系统会自动将结果添加到缓存系统,但如果我更新“users”表,“users”组中的所有键都将被删除。我知道,它不是那么聪明,但它快速且安全(系统还会生成用户列表,并且结果可能是正确的)。
然后,我的问题是:如何在应用程序树中“注入”我的代码?
我首先需要(生成哈希键)完整查询(对于某个表 - 用作组 - ),以及要存储的查询结果。并且,当另一个散列(在该组中)与存储的散列相同时,必须从 memcached 获取该值。
所以,我需要:表名、查询和结果...我认为可以扩展Database类,在execute()方法中实现缓存,但我找不到它!
我的方法正确吗? execute() 方法在哪里?
I'm working in a large project using Kohana 3 framework, actually I need to improve it adding a cache system to reduce the number of MySQL connections.
I'm thinking in develop a basic (but general) module to generate a full query results caching but separately manage the table query results into different groups.
Pex:
cache groups: users, roles, roles_users, etc.
Each group contains all the query results from the correspondant table. So, if I want to get values from 'users', the cache system would automatically add the result to the cache system, but if I update the 'users' table all the keys in 'users' group would be deleted. I know, it's not so smart but it's fast and safe (the system also generate user lists, and the results may be correct).
Then, my question is: ¿Where an how can I make the "injection" of my code in the application tree?
I need, firstly (to generate a hash key) the full query (for a certain table -used as group-), and the result of that query to store. And, when another hash (in the that group) is the same as stored one, the value must be getted from memcached.
So, I need: the table name, the query and the result... I think it's possible extending the Database class, implementing the cache in the execute() method, but I can't find it!
I'm in the correct way? Where the execute() method is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我构建了一个 Kohana 3 模块来完成此任务,但它必须与查询生成器一起使用。它还使用 Memcache 来缓存查询。它在插入/更新/删除时无效。
这是一个链接:
Kohana Memcache 查询缓存
I built a Kohana 3 module that accomplishes this, but it must be used with the query builder. It also uses Memcache to cache the queries. It invalidates on inserts/updates/deletes.
Here's a link:
Kohana Memcache Query Caching