Adds first version of foreign key caching. Not yet working correctly.
Fixes issues with cache. Default cache time: 2 minutes.