Add caching and inversing functions

Add implementation for caching and inversing functions