Skip to content

Commit

Permalink
disable cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
merlos committed Nov 12, 2024
1 parent 828dd98 commit 12fbeee
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions primero-api/primero_api/primero_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CachedLimiterSession(CacheMixin, LimiterMixin, requests.Session):

class PrimeroAPI:

def __init__(self, user, password, api_url, page_size=1000, rate=2, duration=1, cache_expire=3600):
def __init__(self, user, password, api_url, page_size=1000, rate=2, duration=1, cache_expire=0):
'''
Constructor
user: the user name
Expand All @@ -82,7 +82,7 @@ def __init__(self, user, password, api_url, page_size=1000, rate=2, duration=1,
page_size: the size of the page to use for pagination
rate: the rate of requests per duration (default 2 requests per 1 seconds)
duration: the duration in seconds of the rate limit (default 1 seconds)
cache_expire: the duration in seconds to expire the cache (default 3600 seconds)
cache_expire: the duration in seconds to expire the cache (default disabled)
Note: In a pod the cache is removed when the pod is killed or restarted
'''
Expand Down Expand Up @@ -296,13 +296,15 @@ def get_incidents(self, anonymized = True, additional_data:List=None):
return pd.DataFrame(anonymized_incidents)
return pd.DataFrame(incidents)

def get_report_raw(self, report_id: int):
def get_report_raw(self, report_id: int, verbose=False):
"""
Gets the report with the given a report id
returns a dictionary with the content of the report or None if there is an error.
"""

url = self.api_url + 'reports/' + str(report_id)
if verbose:
logger.info('report_id: %s, get_report url=%s', report_id, url)
logger.debug('report_id: %s, get_report url=%s', report_id, url)
return self._call_api_get(url)

Expand Down Expand Up @@ -352,7 +354,7 @@ def get_report(self, report_id: int, lang='en'):
return None
return Report(report_json_dict, lang)

def get_reports(self, lang='en'):
def get_reports(self, lang='en', verbose=False):
'''
Gets the list of reports for the given page and page_size.
Returns a dictionary of Report objects with the id as key and the report as value
Expand All @@ -361,7 +363,10 @@ def get_reports(self, lang='en'):
report_list = self.get_report_list()
for report in report_list:
id = report['id']
if verbose:
logger.info(f'Getting report {id}')
report = self.get_report(id, lang)

if report:
reports[id] = report
return reports
Expand Down

0 comments on commit 12fbeee

Please sign in to comment.