Cache: better compatibility with APCu

cherry-pick of #7043