Working inverse function with cache feature.