Replace global Hash usage with TS::Cache

This adds `thread_safe` gem dependency, do you want me to regenerate `Gemfile` and `arel.gemspec`?