Count tokens with a cache. Still buggy.