Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
basic cache clear
Browse files Browse the repository at this point in the history
  • Loading branch information
eads committed Sep 30, 2016
1 parent 9837dc5 commit 737395d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion elex/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from elex.cli.constants import BANNER, LOG_FORMAT
from elex.cli.decorators import require_date_argument, require_ap_api_key
from elex.cli.hooks import add_election_hook, cachecontrol_logging_hook

from shutil import rmtree

class ElexBaseController(CementBaseController):
class Meta:
Expand Down Expand Up @@ -486,6 +486,33 @@ def next_election(self):

self.app.render(election)

@expose(help="Clear the elex response cache.")
def clear_cache(self):
"""
``elex clear-cache``
Returns data about the next election with an optional date
to start searching.
Command:
.. code:: bash
elex clear-cache
Example output:
"""
from elex import cache
adapter = cache.get_adapter('http://')
self.app.log.info('Clearing cache ({0})'.format(adapter.cache.directory))
try:
rmtree(adapter.cache.directory)
except OSError:
self.app.log.info('No cache entries found.')
else:
self.app.log.info('Cache cleared.')


class ElexApp(CementApp):
class Meta:
Expand Down
2 changes: 1 addition & 1 deletion extras/elex_bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ _elex_complete()
return 0

} &&
complete -F _elex_complete elex
complete -F _elex_complete elex

0 comments on commit 737395d

Please sign in to comment.