diff --git a/jira_select/commands/run.py b/jira_select/commands/run.py index 3464ab3..84fe641 100644 --- a/jira_select/commands/run.py +++ b/jira_select/commands/run.py @@ -17,7 +17,7 @@ def parameter_tuple(value: str) -> Tuple[str, str]: - return tuple(value.split("=", 1)) + return tuple(value.split("=", 1)) # type: ignore class Command(BaseCommand): @@ -72,6 +72,14 @@ def add_arguments(cls, parser: argparse.ArgumentParser) -> None: action="append", type=parameter_tuple, ) + parser.add_argument( + "--no-cache", + "-n", + default=False, + action="store_true", + help="Do not use cached data.", + dest="no_cache", + ) @classmethod def get_help(cls) -> str: @@ -95,6 +103,7 @@ def handle(self) -> None: query_definition, progress_bar=self.options.output is not sys.stdout, parameters=dict(self.options.parameters or []), + enable_cache=not self.options.no_cache, ) with formatter_cls(query, self.options.output) as formatter: for row in query: diff --git a/jira_select/query.py b/jira_select/query.py index 7b2eb59..943aec3 100644 --- a/jira_select/query.py +++ b/jira_select/query.py @@ -301,26 +301,6 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None: pass -class NullCache: - def __init__(self, *args, **kwargs): - pass - - def __getitem__(self, key): - raise KeyError(key) - - def get(self, key, default=None, **kwargs) -> Optional[Any]: - return default - - def touch(self, key, **kwargs): - return - - def set(self, key, value, **kwargs): - return - - def add(self, key, value, **kwargs): - return - - class CounterChannel: def __init__(self): self._counter: int = 2**32 @@ -358,10 +338,9 @@ def __init__( self._functions: Dict[str, Callable] = get_installed_functions(jira) self._progress_bar_enabled = progress_bar - self._cache: Union[MinimumRecencyCache, NullCache] = NullCache() - if enable_cache: - self._cache = MinimumRecencyCache(get_cache_path()) + self._cache = MinimumRecencyCache(get_cache_path()) + self._enable_cache = enable_cache self._parameters: Dict[str, str] = parameters or {} self._field_name_map: Dict[str, str] = FieldNameMap() @@ -370,7 +349,7 @@ def jira(self) -> JIRA: return self._jira @property - def cache(self) -> Union[MinimumRecencyCache, NullCache]: + def cache(self) -> MinimumRecencyCache: return self._cache @property @@ -421,7 +400,7 @@ def _get_cached(self, source: BaseSource) -> Iterator[Result]: ] ) - if self.query.cache: + if self.query.cache and self._enable_cache: try: min_recency, _ = self.query.cache if min_recency is None: