Problem: Scripts that call the same expensive command multiple times waste time re-executing identical operations, especially with API calls or slow queries.
Solution: Add _cache option to cache command results for a specified duration in seconds, returning cached results for subsequent identical calls.
sh.curl(api_url, _cache: 60) # cache for 60 seconds
data1 = sh.curl(api_url, _cache: 60)
data2 = sh.curl(api_url, _cache: 60) # instant, from cache
# Force refresh
sh.curl(api_url, _cache: 60, _refresh_cache: true)
Problem: Scripts that call the same expensive command multiple times waste time re-executing identical operations, especially with API calls or slow queries.
Solution: Add
_cacheoption to cache command results for a specified duration in seconds, returning cached results for subsequent identical calls.