jeremyevans/sequel — pull request #861 by pete (2014-08-11 13:50:03+00:00)
Title: Avoid false positive cache hits when using STI.

I encountered a bug using STI with the caching plugin. The bad interaction is that STI uses multiple classes to load data from the same table, and the caching plugin uses a prefix based on the name of the model's class, so saving as one class and then attempting a load through another class gives stale data. A simplified version of my use-case:

```ruby
Sequel::Model.plugin :caching, TheMemcachedClient
class User < Sequel::Model(:users)
plugin :single_table_inheritance, :type,
model_map: {
'student' => '::User::Student',
# And other classes.
}
class Student < self; end
# And other classes.
end

student = User[user_id]
student.stale = false
student.save # Cached as a User::Student rather than a User!

# Meanwhile, in another HTTP request, or a different process sharing the
# same cache, or something:
user = User[the_same_user_id]
user.stale # => true

```

My workaround was to override ```User.cache_key(pk)``` by means of copy and paste, but this was a little less than ideal. I added a method to allow a user to explicitly override the prefix only (without duplicating the logic around the PK). It's fairly unobtrusive (the behavior doesn't change unless the ```cache_key_prefix``` method is overridden), and it solves the issue.