Removed the cache_clear class method from models and, along with it, removed the class instance variable @caches.

There are a couple of reasons for this. The first reason is that cache_clear relies on state data stored in the class and instances of the class can exist in multiple places. For instance, if you have a number of unicorn instances running, each will have different values in the variable and as such there is no guarantee that calling Model.clear_cache will actually clear the cache for the model. If you really need to clear your cache in a specific way, it should be done on the cache itself.

The second is that in its current state, every time a cache is set or fetches, a new key is added to one of the arrays in @caches. This will often lead to a serious memory leak. Although cache_del will remove the key, caches are far more likely to expire than they are to be manually deleted. To make matters worse, new cache keys are simply pushed into the arrays with no checks for uniqueness, so selecting the same model over and over will still cause the arrays to grow.

Unless this feature can be implemented entirely at the driver end with no state data being stored in the class itself, it is too dangerous of a feature to maintain.
In Sequel, #pk should be used for generically retrieving the primary key of a particular model. The changed code will cause problems if working with a model without a column explicitly named "id."
The check on caching in #after_initialize had some problems:

1. Checking if the primary key is nil wouldn't work if using a composite key since #pk would return an empty array which isn't nil.

2. Since #cache! can be called outside of #after_initialize, the check for whether to cache should be handled by #cache! itself, rather than #after_initialize.

3. There's no reason to cache something that isn't persisted in the database anyway, so using #new? rather than checking for a nil primary key or an array containing nil values is a better solution anyway.
Merge branch 'memory-leak-bugfix' into development
Massive changes to virtually everything.

What began as simply attempting to fix a memory leak and clean up a few issues with query caches turned into a massive rewrite of a large portion of the codebase. While the library in its current state is functional and, for the most part, compatible with the original it still lacks decent documentation, comments and the tests haven't been updated with the changes. With that said, here's a brief overview of what was changed and why:

Caching was model centric before and caching was handled by model hooks. While caching is still dependent on models (something that will change in future revisions) for setup and configuration (i.e. a dataset must respond to #model to work), all of the actual meat of caching happens directly on the datasets now. The after_initialize plugin is no longer necessary since #fetch_rows handles actually setting the cache.

If a dataset meets the requirements to be cached and calls #fetch_rows, the data will be cached. If a dataset calls #update or #delete then the cache is deleted, meaning the next time #fetch_rows is called, the cache will be set again. The downside of this method is that updates do not update the cache since there is no reliable way to do that from an update. When working with single model instances, however, there is an after_save hook which will set the cache again.

A major change that's been made (one that should not affect existing code) is the addition of #cached, #not_cached and #default_cached dataset chaining methods. They allow for a very easy way to force whether a particular dataset is cached or not. For instance: Model.not_cached.with_pk(1) will always hit the database directly. (This has no effects on the after_save hook on the model, however.)

Cache keys are now MD5 hashes of the literal query. This makes for much more compact keys. (Dalli automatically hashes keys over a certain length anyway.)

MessagePack is the default serializer, as before. However, there is no longer a base "Packer" that Marshals. It wasn't even used. Passing in some kind of other serialization library is pretty simple. The msgpack gem is only loaded if no serializer is included.

If the MessagePack serializer is loaded, it will add a to_msgpack instance method to the following classes: BigDecimal, Bignum, Date, Time, Sequel::SQLTime. Dates and times are stored as strings now rather than arrays. While this isn't as efficient when deserializing, it relies on Sequel to make the conversion and alleviates the need for any extra code.

The Redis driver was removed because it adds absolutely no functionality on top of the default driver. The default driver should work. (Testing will resolve that later.)

Logging has been added. Hitting, missing, setting and deleting cache keys are all logged via Sequel's logger now which can help with debugging.

The :query_cache option is no longer used. Since caching is done on datasets now there is no distinction between instance and query caches. There are a couple of new options in its stead however, that can help make up for the lost functionality:

cache_if_limit: If a query has a limit statement and it is less than or equal to this value, the results will be cached. By default this value is set to one, so only queries that are known ahead of time to return a single row are cached. Setting this value to "true" will cache any query with a limit statement, regardless of its size.

cache_by_default: It does exactly what it sounds like. If set to true, all queries get cached unless explicitly designated not to. This is off by default.

As said above, there is still some work to be done but in its current state, the library is functional and mostly a drop in replacement for previous iteration.
Minor stylistic changes made for consistency's sake.
For now, we shouldn't be using syntax that isn't Ruby 1.8 compatible.
Manually set cache keys should be cleared when a dataset is cloned.
Commented DatasetMethods.
Changed the way @is_cacheable is set and works. Instead of using nil as a special value, the variable must be completely unset. The setter also forces the value to true or false. This makes the intent clearer.

The private _is_cacheable? method is now public and renamed to is_cacheable_by_default?
Cleaned up the comments for better RDoc formatting.
More consistency changes.
cache_options can now be set explicitly on a dataset.