I’m not sure how to use your snippet. It has two questionable lines.
Shouldn’t the use_cache boolean value be reversed (i.e., initialized with True instead)
And loader.dataset.set_use_cache(True), how are you executing it after the data looping?