Skip to content

Instantly share code, notes, and snippets.

@judell
Last active November 4, 2022 21:18
Show Gist options
  • Save judell/f849594e912fb1a2fe07ba3e0e1a2f7f to your computer and use it in GitHub Desktop.
Save judell/f849594e912fb1a2fe07ba3e0e1a2f7f to your computer and use it in GitHub Desktop.
explore-steampipe-cache-ttl

A query to cache (or not), should take ~1 (or ~10) secs.

with hn_ids as (
  select generate_series(1, 100) as id
),
hn_urls as (
  select
    'https://hacker-news.firebaseio.com/v0/item/' || h.id || '.json' as hn_api_url
  from
    hn_ids h
)
select 
  *
from
  net_http_request n
where 
  n.url in ( select hn_api_url from hn_urls )

Run it twice.

.cache clear

<query>

Time: 10.7s. Rows fetched: 100. Hydrate calls: 0.

<query>

Time: 1.1s. Rows fetched: 100 (cached). Hydrate calls: 0.

Tweak the settings (in this case turn off the cache).

connection "net" {
  plugin = "net"

  options "connection" {
    cache     = false
    #cache     = true # true, false
    # cache_ttl = 300  # expiration (TTL) in seconds
  }
}

Run it twice.

Time: 9.7s. Rows fetched: 100. Hydrate calls: 0.

Time: 10.2s. Rows fetched: 100. Hydrate calls: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment