Search in sources :

Example 1 with ResourceCacheInvalidationDto

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();
        }
    }
}
Also used : ResourceCacheInvalidationDto(org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto) Cache(javax.cache.Cache)

Example 2 with ResourceCacheInvalidationDto

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 });
}
Also used : ResourceCacheInvalidationDto(org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto)

Example 3 with ResourceCacheInvalidationDto

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]));
}
Also used : JSONObject(org.json.simple.JSONObject) ResourceCacheInvalidationDto(org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject)

Aggregations

ResourceCacheInvalidationDto (org.wso2.carbon.apimgt.api.dto.ResourceCacheInvalidationDto)3 ArrayList (java.util.ArrayList)1 Cache (javax.cache.Cache)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1