Factor out common auth and cache logic