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 If no cache entries exist, elex will close with exit code 65. """ 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.') self.app.exit_code = 65 else: self.app.log.info('Cache cleared.')
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: .. code:: bash 2016-09-30 00:22:56,992 (INFO) cement:app:elex : Clearing cache (/var/folders/z2/plxshs7c43lm_bctxn/Y/elex-cache) 2016-09-30 00:22:56,993 (INFO) cement:app:elex : Cache cleared. """ 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.') self.app.close(64) else: self.app.log.info('Cache cleared.')
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: .. code:: bash 2016-09-30 00:22:56,992 (INFO) cement:app:elex : Clearing cache (/var/folders/z2/plxshs7c43lm_bctxn/Y/elex-cache) 2016-09-30 00:22:56,993 (INFO) cement:app:elex : Cache cleared. If no cache entries exist, elex will close with exit code 65. """ 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.') self.app.exit_code = 65 else: self.app.log.info('Cache cleared.')
def test_elex_cache_miss(self): from elex import cache response = self.api_request('/elections/2016-02-01') http_adapter = cache.get_adapter('http://') try: http_adapter.cache.delete(response.url) except OSError: pass uncached_response = self.api_request('/elections/2016-02-01') self.assertEqual(uncached_response.from_cache, False)