Copied code for vector caching as a starting point
final working versions of the caching functions