Skip to content

Commit

Permalink
Merge pull request #1112 from jqnatividad/fetch_no-cache_option
Browse files Browse the repository at this point in the history
add --no-cache option
  • Loading branch information
jqnatividad authored Jul 6, 2023
2 parents e9046c5 + 2c2b5ef commit e62894f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ By default, it will connect to a local Redis instance at redis://127.0.0.1:6379/
with a cache expiry Time-to-Live (TTL) of 2,419,200 seconds (28 days),
and cache hits NOT refreshing the TTL of cached values.
If you don't want responses to be cached, use the --no-cache flag.
Set the environment variables QSV_REDIS_CONNSTR, QSV_REDIS_TTL_SECONDS and
QSV_REDIS_TTL_REFRESH to change default Redis settings.
Expand Down Expand Up @@ -142,6 +144,7 @@ Fetch options:
Set to zero (0) to continue despite errors.
[default: 10 ]
--store-error On error, store error code/message instead of blank value.
--no-cache Do not cache responses.
--cache-error Cache error responses even if a request fails. If an identical URL is requested,
the cached error is returned. Otherwise, the fetch is attempted again
for --max-retries.
Expand Down Expand Up @@ -228,6 +231,7 @@ struct Args {
flag_max_retries: u8,
flag_max_errors: u64,
flag_store_error: bool,
flag_no_cache: bool,
flag_cache_error: bool,
flag_cookies: bool,
flag_user_agent: Option<String>,
Expand Down Expand Up @@ -666,6 +670,18 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
wwarn!(r#"Cannot remove Redis key "{key}""#);
};
}
} else if args.flag_no_cache {
final_response = get_response(
&url,
&client,
&limiter,
&jql_selector,
args.flag_store_error,
args.flag_pretty,
include_existing_columns,
args.flag_max_retries,
);
was_cached = false;
} else {
intermediate_value = get_cached_response(
&url,
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/fetchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and cache hits NOT refreshing the TTL of cached values.
Note that the default values are the same as the fetch command, except fetchpost creates the
cache at database 2, as opposed to database 1 with fetch.
If you don't want responses to be cached, use the --no-cache flag.
Set the environment variables QSV_FP_REDIS_CONNSTR, QSV_FP_REDIS_TTL_SECONDS and
QSV_FP_REDIS_TTL_REFRESH respectively to change default Redis settings.
Expand Down Expand Up @@ -133,6 +135,7 @@ Fetchpost options:
Set to zero (0) to continue despite errors.
[default: 10 ]
--store-error On error, store error code/message instead of blank value.
--no-cache Do not cache responses.
--cache-error Cache error responses even if a request fails. If an identical URL is requested,
the cached error is returned. Otherwise, the fetch is attempted again
for --max-retries.
Expand Down Expand Up @@ -220,6 +223,7 @@ struct Args {
flag_max_retries: u8,
flag_max_errors: u64,
flag_store_error: bool,
flag_no_cache: bool,
flag_cache_error: bool,
flag_cookies: bool,
flag_user_agent: Option<String>,
Expand Down Expand Up @@ -668,6 +672,20 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
wwarn!(r#"Cannot remove Redis key "{key}""#);
};
}
} else if args.flag_no_cache {
final_response = get_response(
&url,
&form_body_jsonmap,
&client,
&limiter,
&jql_selector,
args.flag_store_error,
args.flag_pretty,
args.flag_compress,
include_existing_columns,
args.flag_max_retries,
);
was_cached = false;
} else {
intermediate_value = get_cached_response(
&url,
Expand Down

0 comments on commit e62894f

Please sign in to comment.