refactor cache management to reduce the scope of config variables See merge request to-be-continuous/python!103