Advertisement
Advertisement


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


Question

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?

2010/02/05
1
2
2/5/2010 4:23:22 AM

Accepted Answer

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;
2008/08/30
5
8/30/2008 12:54:08 AM


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.

2008/09/06

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

2010/01/05

Source: https://stackoverflow.com/questions/35480
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]