简体   繁体   English

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

[英]How can I clear Class::DBI's internal cache?

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. 我目前正在为现有的数据库结构进行Class :: DBI的大型实现,并且遇到了从Class :: DBI清除缓存的问题。 This is a mod_perl implementation, so an instance of a class can be quite old between times that it is accessed. 这是一个mod_perl实现,因此类的实例在两次访问之间可能很旧。 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. 现在,当我将clear_object_index()添加到DESTROY方法时,它似乎正在运行,但实际上并没有清空缓存。 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. purge_object_index_every表示每n个请求清除一次索引。 Setting this to "1" or "0", seems to clear the index... sometimes. 将此设置为“ 1”或“ 0”似乎会清除索引...有时。 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? 有什么建议可以解决吗?

The " common problems " page on the Class::DBI wiki has a section on this subject. Class :: DBI Wiki上的“ 常见问题 ”页面上有关于此主题的部分 The simplest solution is to disable the live object index entirely using: 最简单的解决方案是完全使用以下方法禁用活动对象索引:

$Class::DBI::Weaken_Is_Available = 0;

$obj->dbi_commit(); $ 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. 您告诉它每2000个对象加载检查一次对象缓存,并删除所有无效引用以节省内存。 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. 听起来您尝试执行的操作应该可以正常工作,但是您的SQL或其他地方可能存在问题,导致INSERT或UPDATE无法正常工作。 Are you doing error checking for each database query as the perldoc suggests? 您是否按照perldoc的建议对每个数据库查询进行错误检查? 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! 希望这可以帮助!

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

我应该注意不赞成使用Class :: DBI,而应将代码移植DBIx :: Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM