Primitives now each recieve a unique ID which is used for indexing the LRUCache.

This simplifies code a bit, and paves the way towards optionally having
per-thread geometry caches.
Added asserts for tracking down a bug.