Skip to content

Commit

Permalink
Add --no-cache flag allowing you to disable reading from cached results.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Mar 4, 2023
1 parent a80f31b commit f89efa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
11 changes: 10 additions & 1 deletion jira_select/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
29 changes: 4 additions & 25 deletions jira_select/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f89efa0

Please sign in to comment.