A caching class with automatic cleanup