如何清除 Class::DBI 的内部缓存?

发布于 2024-07-04 17:49:33 字数 518 浏览 13 评论 0 原文

我目前正在为现有数据库结构开发 Class::DBI 的大型实现,并且在清除 Class::DBI 缓存时遇到问题。 这是一个 mod_perl 实现,因此类的实例在两次访问之间可能已经很旧了。 从手册页中我发现了两个选项:

Music::DBI->clear_object_index();

和:

Music::Artist->purge_object_index_every(2000);

现在,当我将clear_object_index() 添加到 DESTROY 方法时,它似乎在运行,但实际上并没有清空缓存。 我可以手动更改数据库,重新运行请求,但它仍然是旧版本。 purge_object_index_every 表示每 n 个请求清除索引。 将其设置为“1”或“0”,似乎有时会清除索引。 我希望这两者之一能够发挥作用,但由于某种原因,它并不每次都能发挥作用。 大约五分之一。

有什么建议可以解决这个问题吗?

I'm currently working on a large implementation of Class::DBI for an existing database structure, and am running into a problem with clearing the cache from Class::DBI. This is a mod_perl implementation, so an instance of a class can be quite old between times that it is accessed.
From the man pages I found two options:

Music::DBI->clear_object_index();

And:

Music::Artist->purge_object_index_every(2000);

Now, when I add clear_object_index() to the DESTROY method, it seems to run, but doesn't actually empty the cache. I am able to manually change the database, re-run the request, and it is still the old version.
purge_object_index_every says that it clears the index every n requests. Setting this to "1" or "0", seems to clear the index... sometimes. I'd expect one of those two to work, but for some reason it doesn't do it every time. More like 1 in 5 times.

Any suggestions for clearing this out?

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

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

发布评论

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

评论(4

爺獨霸怡葒院 2024-07-11 17:49:33

我应该注意到 Class::DBI 已被弃用,您应该将代码移植到 DBIx::Class 相反。

I should note that Class::DBI is deprecated and you should port your code to DBIx::Class instead.

稍尽春風 2024-07-11 17:49:33

我过去成功地使用了remove_from_object_index,因此当调用修改数据库的页面时,它总是在缓存中显式重置该对象作为确认页面的一部分。

I've used remove_from_object_index successfully in the past, so that when a page is called that modifies the database, it always explicitly reset that object in the cache as part of the confirmation page.

楠木可依 2024-07-11 17:49:33

$obj->dbi_commit(); 如果您有未完成的交易,可能就是您正在寻找的。 然而,这种情况不太可能发生,因为它往往会在销毁时自动完成任何延迟的交易。

当您执行此操作时:

Music::Artist->purge_object_index_every(2000);

您是在告诉它每加载 2000 个对象就检查一次对象缓存,并删除所有死引用以节省内存使用。 我认为这根本不是你想要的。

此外,

Music::DBI->clear_object_index();

从活动对象索引中删除所有对象。 我根本不知道这会有什么帮助; 实际上,它并没有将它们刷新到磁盘。

听起来您想要做的事情应该按照您的方式工作得很好,但是您的 SQL 或其他地方可能存在问题,导致 INSERT 或 UPDATE 无法工作。 您是否按照 perldoc 的建议对每个数据库查询进行错误检查? 也许您可以从那里开始或在数据库错误日志中开始,观察查询以了解它们为何未完成或它们是否到达。

希望这可以帮助!

$obj->dbi_commit(); may be what you are looking for if you have uncompleted transactions. However, this is not very likely the case, as it tends to complete any lingering transactions automatically on destruction.

When you do this:

Music::Artist->purge_object_index_every(2000);

You are telling it to examine the object cache every 2000 object loads and remove any dead references to conserve memory use. I don't think that is what you want at all.

Furthermore,

Music::DBI->clear_object_index();

Removes all objects form the live object index. I don't know how this would help at all; it's not flushing them to disk, really.

It sounds like what you are trying to do should work just fine the way you have it, but there may be a problem with your SQL or elsewhere that is preventing the INSERT or UPDATE from working. Are you doing error checking for each database query as the perldoc suggests? Perhaps you can begin there or in your database error logs, watching the queries to see why they aren't being completed or if they ever arrive.

Hope this helps!

佞臣 2024-07-11 17:49:33

常见问题”页面.class-dbi.com/wiki" rel="nofollow noreferrer">Class::DBI wiki 有一个 关于此主题的部分。 最简单的解决方案是完全禁用活动对象索引:

$Class::DBI::Weaken_Is_Available = 0;

The "common problems" page on the Class::DBI wiki has a section on this subject. The simplest solution is to disable the live object index entirely using:

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