disable cache until we can fix on cloud deployment

This commit is contained in:
James Moffet
2022-07-26 11:17:43 -07:00
parent e6b36becf1
commit 4c25a81004
11 changed files with 88 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
from app.extensions import redis_client
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
from flask import current_app
class JobApiClient(NotifyAdminAPIClient):
@@ -100,11 +101,12 @@ class JobApiClient(NotifyAdminAPIClient):
data = _attach_current_user(data)
job = self.post(url='/service/{}/job'.format(service_id), data=data)
redis_client.set(
'has_jobs-{}'.format(service_id),
b'true',
ex=int(cache.DEFAULT_TTL),
)
if current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
redis_client.set(
'has_jobs-{}'.format(service_id),
b'true',
ex=int(cache.DEFAULT_TTL),
)
return job

View File

@@ -5,6 +5,8 @@ from notifications_python_client.errors import HTTPError
from app.extensions import redis_client
from app.notify_client import NotifyAdminAPIClient, cache
from flask import current_app
class OrganisationsClient(NotifyAdminAPIClient):
@@ -53,11 +55,12 @@ class OrganisationsClient(NotifyAdminAPIClient):
def update_organisation(self, org_id, cached_service_ids=None, **kwargs):
api_response = self.post(url="/organisations/{}".format(org_id), data=kwargs)
if cached_service_ids:
redis_client.delete(*map('service-{}'.format, cached_service_ids))
if current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
if cached_service_ids:
redis_client.delete(*map('service-{}'.format, cached_service_ids))
if 'name' in kwargs:
redis_client.delete(f'organisation-{org_id}-name')
if 'name' in kwargs:
redis_client.delete(f'organisation-{org_id}-name')
return api_response

View File

@@ -1,5 +1,5 @@
from datetime import datetime
from flask import current_app
from notifications_utils.clients.redis import daily_limit_cache_key
from app.extensions import redis_client
@@ -138,7 +138,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
# @cache.delete('service-{service_id}-templates')
# @cache.delete_by_pattern('service-{service_id}-template-*')
def archive_service(self, service_id, cached_service_user_ids):
if cached_service_user_ids:
if cached_service_user_ids and current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
redis_client.delete(*map('user-{}'.format, cached_service_user_ids))
return self.post('/service/{}/archive'.format(service_id), data=None)
@@ -595,7 +595,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
broadcast channel is one of "operator", "test", "severe", "government"
provider_restriction is one of "all", "three", "o2", "vodafone", "ee"
"""
if cached_service_user_ids:
if cached_service_user_ids and current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
redis_client.delete(*map('user-{}'.format, cached_service_user_ids))
data = {
@@ -608,7 +608,14 @@ class ServiceAPIClient(NotifyAdminAPIClient):
def get_notification_count(self, service_id):
# if cache is not set return 0
count = redis_client.get(daily_limit_cache_key(service_id)) or 0
current_app.logger.info("Pinging redis for daily_limit_cache_key(service_id): {}".format(daily_limit_cache_key(service_id)))
current_app.logger.info("Redis url is: {}".format( current_app.config['REDIS_URL'] ))
current_app.logger.info("Redis enabled is: {}".format( current_app.config['REDIS_ENABLED'] ))
if current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
count = redis_client.get(daily_limit_cache_key(service_id)) or 0
else:
count = 0
return int(count)

View File

@@ -48,7 +48,7 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient):
'folders': list(folder_ids),
})
if template_ids:
if template_ids and current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']:
redis_client.delete(*(f'service-{service_id}-template-{id}-version-None' for id in template_ids))
# @cache.delete('service-{service_id}-template-folders')