fix buggy cache trim method