Shopify/identity_cache — pull request #91 by dylanahsmith (2013-09-23 23:06:09+00:00)
Title: Add IdentityCache.cache_namespace which can be a string or proc.

@camilo & @arthurnn for review

## Problem

If someone wants to provide a cache namespace, then they could override the rails_cache_key_namespace on the model. Doing this across all models could be done using a mixin, however, if that mixin is included before IdentityCache, then it wouldn't be used.

A simple use case would be vertical sharding, where some models are moved to a different database. In this case there should be an easy way to generically provide this namespace, but have it be model dependant.

## Solution

Add an IdentityCache.cache_namespace attribute which can take a string or a Proc, initialized to the same default namespace we previously used. rails_cache_key_namespace will return the string or the result of calling the Proc with the model as an argument.

Example:

```
old_ns = IdentityCache.cache_namespace
IdentityCache.cache_namespace = proc { |model| "#{old_ns}#{model.connection_config[:database]}:" }
```