Refactor cache logic for configurable backends