Adding a local thread registry to store local caches.

I've added a registry to store local caches. This should decrease the number of thread locals a lot because currently, every time you create a new local cache, you create a new thread local.

I'm using the ``PerThreadRegistry`` module to create a single registry object.