How does the $cacheFactory service work, and how can it optimize application performance?

$cacheFactory caches data, reducing redundant API calls and resource usage by storing frequently accessed data. This approach lowers server load and improves responsiveness by ensuring that cached results are reused instead of fetched repeatedly.

var cache = $cacheFactory('myCache');
cache.put('key', 'value');