I don't think a "prefixes" cache exists, you need to query the DB for that.
Not that I like the idea, along with the fact you're using get_thread() in there, because it means there's potentially two queries being run in a loop, but as far as getting it to work, it's not an issue.
Also, your logic seems to be a bit whacky here:
A few other things:
Hook doesn't exist. Closest thing I found was admin_config_thread_prefixes_start, which obviously won't work with the same processing function.
lastposttid isn't guaranteed to be set (ie forum with no posts) - it might be a good idea to check that in your code.
Hope that helps.