<p>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:</p>

<pre><code>Music::DBI-&gt;clear_object_index();
</code></pre>

<p>And:</p>

<pre><code>Music::Artist-&gt;purge_object_index_every(2000);
</code></pre>

<p>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.</p>

<p>Any suggestions for clearing this out?</p>

[{'answer_id': 35529, 'author': 'John Siracusa', 'author_id': 164, 'author_profile': 'https://Stackoverflow.com/users/164', 'pm_score': 4, 'selected': True, 'text': '<p>The "<a href="http://wiki.class-dbi.com/wiki/Common_problems" rel="nofollow noreferrer">common problems</a>" page on the <a href="http://wiki.class-dbi.com/wiki" rel="nofollow noreferrer">Class::DBI wiki</a> has a <a href="http://wiki.class-dbi.com/wiki/Common_problems#Old_data_due_to_object_index" rel="nofollow noreferrer">section</a> on this subject.  The simplest solution is to disable the live object index entirely using:</p>\n\n<pre><code>$Class::DBI::Weaken_Is_Available = 0;\n</code></pre>\n'}, {'answer_id': 47568, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 0, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 47599, 'author': 'Sean', 'author_id': 4919, 'author_profile': 'https://Stackoverflow.com/users/4919', 'pm_score': 2, 'selected': False, 'text': "<p>$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.</p>\n\n<p>When you do this:</p>\n\n<pre><code>Music::Artist-&gt;purge_object_index_every(2000);\n</code></pre>\n\n<p>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.</p>\n\n<p>Furthermore,</p>\n\n<pre><code>Music::DBI-&gt;clear_object_index();\n</code></pre>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>Hope this helps!</p>\n"}, {'answer_id': 2007971, 'author': 'Shlomi Fish', 'author_id': 7709, 'author_profile': 'https://Stackoverflow.com/users/7709', 'pm_score': -1, 'selected': False, 'text': '<p>I should note that Class::DBI is deprecated and you should port your code to <a href="http://search.cpan.org/dist/DBIx-Class/" rel="nofollow noreferrer">DBIx::Class</a> instead.</p>\n'}]
['https://Stackoverflow.com/questions/35480', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3421/']