Reduced memory usage

Added a gc.collect() call after updating the cache to reduce memory
usage.