Cache service data retention in Redis

Adds caching for service data retention. This removes separate API
client methods to retrieve individual data retention records by id
or type in favor of a single method that fetches and caches all
retention settings configured for the service. This makes it much
easier to invalidate cache when settings change.

Lookup by id or type is provided by helper methods in the service
model.
This commit is contained in:
Alexey Bezhan
2018-12-03 17:19:38 +00:00
parent 8aeea9929f
commit 7a7a9ae854
9 changed files with 62 additions and 72 deletions

View File

@@ -488,6 +488,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
}
return self.post("/service/{}/delivery-receipt-api".format(service_id), data)
@cache.delete('service-{service_id}-data-retention')
def create_service_data_retention(self, service_id, notification_type, days_of_retention):
data = {
"notification_type": notification_type,
@@ -496,20 +497,16 @@ class ServiceAPIClient(NotifyAdminAPIClient):
return self.post("/service/{}/data-retention".format(service_id), data)
@cache.delete('service-{service_id}-data-retention')
def update_service_data_retention(self, service_id, data_retention_id, days_of_retention):
data = {
"days_of_retention": days_of_retention
}
return self.post("/service/{}/data-retention/{}".format(service_id, data_retention_id), data)
@cache.set('service-{service_id}-data-retention')
def get_service_data_retention(self, service_id):
return self.get("/service/{}/data-retention".format(service_id))
def get_service_data_retention_by_notification_type(self, service_id, notification_type):
return self.get("/service/{}/data-retention/notification-type/{}".format(service_id, notification_type))
def get_service_data_retention_by_id(self, service_id, data_retention_id):
return self.get("service/{}/data-retention/{}".format(service_id, data_retention_id))
service_api_client = ServiceAPIClient()