@@ -105,12 +105,6 @@ def run():
105
105
export GRAFANA_TOKEN=eyJrIjoiWHg...dGJpZCI6MX0=
106
106
grafana-wtf find luftdaten
107
107
108
- # Use infinite cache expiration time, essentially caching forever.
109
- grafana-wtf find '#299c46' --cache-ttl=inf
110
-
111
- # Set cache expiration time to zero, essentially disabling the cache.
112
- grafana-wtf find geohash --cache-ttl=0
113
-
114
108
# Search keyword within list of specific dashboards.
115
109
grafana-wtf --select-dashboard=_JJ22OZZk,5iGTqNWZk find grafana-worldmap
116
110
@@ -139,6 +133,18 @@ def run():
139
133
# Output full history table in Markdown format
140
134
grafana-wtf log --format=tabular:pipe
141
135
136
+ Cache control:
137
+
138
+ # Use infinite cache expiration time, essentially caching forever.
139
+ grafana-wtf find '#299c46' --cache-ttl=inf
140
+
141
+ # Set cache expiration time to zero, essentially disabling the cache.
142
+ grafana-wtf find geohash --cache-ttl=0
143
+
144
+ # Setting `--cache-ttl` per environment variable `CACHE_TTL` is also possible
145
+ export CACHE_TTL=infinite
146
+ grafana-wtf find geohash
147
+
142
148
"""
143
149
144
150
# Parse command line arguments
@@ -159,11 +165,17 @@ def run():
159
165
grafana_url = options ["grafana-url" ] or os .getenv ("GRAFANA_URL" )
160
166
grafana_token = options ["grafana-token" ] or os .getenv ("GRAFANA_TOKEN" )
161
167
168
+ # Read cache expiration time setting, environment variable takes precedence.
169
+ if "CACHE_TTL" in os .environ :
170
+ cache_ttl = os .getenv ("CACHE_TTL" )
171
+ else :
172
+ cache_ttl = options ["cache-ttl" ]
173
+
162
174
# Compute cache expiration time.
163
175
try :
164
- cache_ttl = int (options [ "cache-ttl" ] )
165
- except :
166
- if not options [ "cache-ttl" ] or "infinite" .startswith (options [ "cache-ttl" ] .lower ()):
176
+ cache_ttl = int (cache_ttl )
177
+ except ValueError :
178
+ if not cache_ttl or "infinite" .startswith (cache_ttl .lower ()):
167
179
cache_ttl = None
168
180
else :
169
181
raise
0 commit comments