Refactor user caching to exclude code duplication