use of org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto in project carbon-apimgt by wso2.
the class CacheInvalidationServiceImpl method invalidateResourceCache.
@Override
public void invalidateResourceCache(String apiContext, String apiVersion, ResourceCacheInvalidationDto[] uriTemplates) {
boolean isTenantFlowStarted = false;
int tenantDomainIndex = apiContext.indexOf("/t/");
String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
if (tenantDomainIndex != -1) {
String temp = apiContext.substring(tenantDomainIndex + 3, apiContext.length());
tenantDomain = temp.substring(0, temp.indexOf('/'));
}
try {
isTenantFlowStarted = startTenantFlow(tenantDomain);
Cache cache = CacheProvider.getResourceCache();
if (apiContext.contains(APIConstants.POLICY_CACHE_CONTEXT)) {
if (log.isDebugEnabled()) {
log.debug("Cleaning cache for policy update for tenant " + tenantDomain);
}
cache.removeAll();
} else {
String apiCacheKey = APIUtil.getAPIInfoDTOCacheKey(apiContext, apiVersion);
if (cache.containsKey(apiCacheKey)) {
cache.remove(apiCacheKey);
}
for (ResourceCacheInvalidationDto uriTemplate : uriTemplates) {
String resourceVerbCacheKey = APIUtil.getResourceInfoDTOCacheKey(apiContext, apiVersion, uriTemplate.getResourceURLContext(), uriTemplate.getHttpVerb());
if (cache.containsKey(resourceVerbCacheKey)) {
cache.remove(resourceVerbCacheKey);
}
}
}
} finally {
if (isTenantFlowStarted) {
endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto in project carbon-apimgt by wso2.
the class CacheInvalidationServiceImpl method invalidateResourceCache.
public void invalidateResourceCache(String apiContext, String apiVersion, String resourceURLContext, String httpVerb) {
ResourceCacheInvalidationDto uriTemplate = new ResourceCacheInvalidationDto();
uriTemplate.setResourceURLContext(resourceURLContext);
uriTemplate.setHttpVerb(httpVerb);
invalidateResourceCache(apiContext, apiVersion, new ResourceCacheInvalidationDto[] { uriTemplate });
}
use of org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto in project carbon-apimgt by wso2.
the class APIMgtGatewayCacheMessageListener method handleResourceCacheInvalidationMessage.
private void handleResourceCacheInvalidationMessage(JSONObject jsonValue) throws ParseException {
String apiContext = (String) jsonValue.get("apiContext");
String apiVersion = (String) jsonValue.get("apiVersion");
JSONArray resources = (JSONArray) jsonValue.get("resources");
List<ResourceCacheInvalidationDto> resourceCacheInvalidationDtoList = new ArrayList<>();
for (Object resource : resources) {
JSONObject uriTemplate = (JSONObject) resource;
String resourceURLContext = (String) uriTemplate.get("resourceURLContext");
String httpVerb = (String) uriTemplate.get("httpVerb");
ResourceCacheInvalidationDto uriTemplateDto = new ResourceCacheInvalidationDto();
uriTemplateDto.setHttpVerb(httpVerb);
uriTemplateDto.setResourceURLContext(resourceURLContext);
resourceCacheInvalidationDtoList.add(uriTemplateDto);
}
ServiceReferenceHolder.getInstance().getCacheInvalidationService().invalidateResourceCache(apiContext, apiVersion, resourceCacheInvalidationDtoList.toArray(new ResourceCacheInvalidationDto[0]));
}
Aggregations