I have an after_destroy model callback that regenerates cache after the model instance has been destroyed. It does this by calling open("http://domain.com/page-to-cache") for as many pages as need to be re-cached.
The problem is that the model instance apparently isn’t fully destroyed yet at this time, because those open url requests still register its presence, and the regenerated cache looks exactly like the pre-destroy cache. How can I run those calls after the model instance has been actually destroyed?
You may be able to use an
after_commitcallback to do something after the entire transaction has gone through to the database. This is different depending on the version of Rails you’re using (2.3.x versus 3.x.x), but is essentially something like the following:You can read some documentation about the Rails 3
after_commitcallback here. If your version of Rails doesn’t have anafter_commithook, you can try using this gem which will provide the functionality.