org.codeforamerica.open311.internals.caching
Interface Cache

All Known Implementing Classes:
AbstractCache, AndroidCache, NoCache, RegularJavaCache

public interface Cache

Specifies all the operations needed to do data caching and avoid useless and slow network requests.

Author:
Santiago MunĂ­n

Nested Class Summary
static class Cache.CacheableOperation
          Set of operations which will be cached.
 
Method Summary
 void deleteCache()
          Deletes the cache.
 ServiceDefinition retrieveCachedServiceDefinition(String endpointUrl, String serviceCode)
          Looks for a cached service definition.
 ServiceDiscoveryInfo retrieveCachedServiceDiscoveryInfo(City city)
          Looks for the service discovery of a given city in the local cache.
 List<Service> retrieveCachedServiceList(String endpointUrl)
          Looks for a cached list of services.
 ServiceRequest retrieveCachedServiceRequest(String endpointUrl, String serviceRequestId)
          Looks for a cached GET service request response.
 List<ServiceRequest> retrieveCachedServiceRequests(String endpointUrl, GETServiceRequestsFilter filter)
          Looks for a cached GET service requests response.
 String retrieveCitiesInfo()
          Looks for the endpoints-service discovery relationships.
 void saveCitiesInfo(String data)
          Saves the endpoints-service discovery relationships.
 void saveListOfServices(String endpointUrl, List<Service> services)
          Saves a list of Service objects related to an endpoint.
 void saveServiceDefinition(String endpointUrl, String serviceCode, ServiceDefinition serviceDefinition)
          Saves a service definition.
 void saveServiceDiscovery(City city, ServiceDiscoveryInfo serviceDiscovery)
          Saves a object related to a city.
 void saveServiceRequestList(String endpointUrl, GETServiceRequestsFilter filter, List<ServiceRequest> requests)
          Saves a list of service requests.
 void saveSingleServiceRequest(String endpointUrl, String serviceRequestId, ServiceRequest request)
          Saves a service request.
 void setCustomTimeToLive(Cache.CacheableOperation operation, int timeToLiveInHours)
          Set a custom time to live to a given operation.
 

Method Detail

saveCitiesInfo

void saveCitiesInfo(String data)
Saves the endpoints-service discovery relationships.

Parameters:
data - A JSON list.

retrieveCitiesInfo

String retrieveCitiesInfo()
Looks for the endpoints-service discovery relationships.

Returns:
A JSON list or null if it wasn't found.

saveServiceDiscovery

void saveServiceDiscovery(City city,
                          ServiceDiscoveryInfo serviceDiscovery)
Saves a object related to a city.

Parameters:
city - City related to the requested service discovery.
serviceDiscovery - The obtained service discovery.

retrieveCachedServiceDiscoveryInfo

ServiceDiscoveryInfo retrieveCachedServiceDiscoveryInfo(City city)
Looks for the service discovery of a given city in the local cache.

Parameters:
city - City of interest.
Returns:
The service discovery of the given city of null if it isn't cached.

saveListOfServices

void saveListOfServices(String endpointUrl,
                        List<Service> services)
Saves a list of Service objects related to an endpoint.

Parameters:
endpointUrl - Url of the endpoint.
services - Obtained services.

retrieveCachedServiceList

List<Service> retrieveCachedServiceList(String endpointUrl)
Looks for a cached list of services.

Parameters:
endpointUrl - Url of the endpoint.
Returns:
The list of services or null if they aren't cached.

saveServiceDefinition

void saveServiceDefinition(String endpointUrl,
                           String serviceCode,
                           ServiceDefinition serviceDefinition)
Saves a service definition.

Parameters:
endpointUrl - Url of the endpoint.
serviceCode - Code of the service.
serviceDefinition - Obtained definition from the server.

retrieveCachedServiceDefinition

ServiceDefinition retrieveCachedServiceDefinition(String endpointUrl,
                                                  String serviceCode)
Looks for a cached service definition.

Parameters:
endpointUrl - Url of the endpoint.
serviceCode - Service code of the desired service.
Returns:
A service definition or null if it isn't cached.

saveServiceRequestList

void saveServiceRequestList(String endpointUrl,
                            GETServiceRequestsFilter filter,
                            List<ServiceRequest> requests)
Saves a list of service requests.

Parameters:
endpointUrl - Url of the endpoint.
filter - Filter sent to the endpoint.
requests - Obtained list of requests.

retrieveCachedServiceRequests

List<ServiceRequest> retrieveCachedServiceRequests(String endpointUrl,
                                                   GETServiceRequestsFilter filter)
Looks for a cached GET service requests response.

Parameters:
endpointUrl - Url of the endpoint.
filter - The desired filter.
Returns:
A list of ServiceRequest or null if they aren't cached.

saveSingleServiceRequest

void saveSingleServiceRequest(String endpointUrl,
                              String serviceRequestId,
                              ServiceRequest request)
Saves a service request.

Parameters:
endpointUrl - Url of the endpoint.
serviceRequestId - Id of the requested service request.
request - Obtained service request.

retrieveCachedServiceRequest

ServiceRequest retrieveCachedServiceRequest(String endpointUrl,
                                            String serviceRequestId)
Looks for a cached GET service request response.

Parameters:
endpointUrl - Url of the endpoint.
serviceRequestId - The service request's id.
Returns:
A ServiceRequest or null if it wasn't cached.

deleteCache

void deleteCache()
Deletes the cache.


setCustomTimeToLive

void setCustomTimeToLive(Cache.CacheableOperation operation,
                         int timeToLiveInHours)
Set a custom time to live to a given operation.

Parameters:
operation - Operation which time to live will be changed.
timeToLiveInHours - New time to live (in hours).


Copyright © 2013 Code for America. All Rights Reserved.