Skip to content

Commit c43eb56

Browse files
committed
Improve caching
- Use cache database location within user folder - Send cache database location to log - Reduce default cache TTL from five minutes to 60 seconds
1 parent d0251a0 commit c43eb56

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ in progress
1010
- Add URLs to dashboard variables and panel view/edit pages to the output of
1111
the ``find`` subcommand. Thanks, @oplehto.
1212
- Improve display of progressbar wrt. being interrupted by logging output.
13+
- Improve caching
14+
15+
- Use cache database location within user folder
16+
- c cache database location to log
17+
- Reduce default cache TTL from five minutes to 60 seconds
1318

1419
2022-06-19 0.13.4
1520
=================

grafana_wtf/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def run():
4545
--select-dashboard=<uuid> Restrict operation to dashboard by UID.
4646
Can be a list of comma-separated dashboard UIDs.
4747
--format=<format> Output format. [default: json]
48-
--cache-ttl=<cache-ttl> Time-to-live for the request cache in seconds. [default: 300]
48+
--cache-ttl=<cache-ttl> Time-to-live for the request cache in seconds. [default: 60]
4949
--drop-cache Drop cache before requesting resources
5050
--concurrency=<concurrency> Run multiple requests in parallel. [default: 5]
5151
--dry-run Dry-run mode for the `replace` subcommand.

grafana_wtf/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ def __init__(self, grafana_url, grafana_token):
4848
self.debug = log.getEffectiveLevel() == logging.DEBUG
4949
self.progressbar = not self.debug
5050

51-
def enable_cache(self, expire_after=300, drop_cache=False):
51+
def enable_cache(self, expire_after=60, drop_cache=False):
5252
if expire_after is None:
53-
log.info(f"Setting up response cache to never expire (infinite caching)")
53+
log.info(f"Configure response cache to never expire (infinite caching)")
5454
else:
55-
log.info(f"Setting up response cache to expire after {expire_after} seconds")
56-
requests_cache.install_cache(expire_after=expire_after)
55+
log.info(f"Configure response cache to expire after {expire_after} seconds")
56+
requests_cache.install_cache(expire_after=expire_after, use_cache_dir=True)
57+
cache_database_file = requests_cache.get_cache().db_path
58+
log.info(f"Response cache database location is {cache_database_file}")
5759
if drop_cache:
60+
log.info("Dropping response cache")
5861
self.clear_cache()
5962

6063
return self

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"grafana-client>=2.1.0,<4",
1919
"jsonpath-rw>=1.4.0,<2",
2020
# Caching
21-
"requests-cache>=0.5.2,<1",
21+
"requests-cache>=0.8.0,<1",
2222
# Output
2323
"tabulate>=0.8.5,<0.10",
2424
"colored>=1.4.3,<2",

0 commit comments

Comments
 (0)