Improve cache api and add tests for it

Part of the improvement is fixing the corner case where calling
cache.get('get') would return the get function itself. This is solved by
storing cache entries in their own dedicated table.