Added finally block to cache clearing.

As suggested, now the cache is always cleared upon user-level function exit,
assuming it was supposed to be cleared, even if an exception was raised.
Also deleted some older commented out code.