<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dev_cache(self, device, key=None):
 """Get a cached value for a device."""

        device_cache = self._cache.get(CONST.DEVICES, {}).get(device.device_id)

        if device_cache and key:
            return device_cache.get(key)

        return device_cache