diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java index d52a20535d4f..b87753bd7d4b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/InMemoryAPIDeployer.java @@ -46,6 +46,8 @@ import org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder; import org.wso2.carbon.apimgt.gateway.service.APIGatewayAdmin; import org.wso2.carbon.apimgt.impl.APIConstants; +import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; +import org.wso2.carbon.apimgt.impl.caching.CacheInvalidationServiceImpl; import org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto; import org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties; import org.wso2.carbon.apimgt.impl.dto.GatewayCleanupSkipList; @@ -371,6 +373,13 @@ private void unDeployAPI(APIGatewayAdmin apiGatewayAdmin, DeployAPIInGatewayEven DataHolder.getInstance().getApiToCertificatesMap().remove(gatewayEvent.getUuid()); DataHolder.getInstance().removeKeyManagerToAPIMapping(gatewayAPIDTO.getApiId()); DataHolder.getInstance().releaseCache(generateAPIKeyForEndpoints(gatewayAPIDTO)); + if (isAPIResourceValidationEnabled()) { + new CacheInvalidationServiceImpl().invalidateResourceCache( + gatewayEvent.getContext(), + gatewayEvent.getVersion(), + gatewayEvent.getTenantDomain(), + new ArrayList<>()); + } } } @@ -387,6 +396,22 @@ public void unDeployAPI(DeployAPIInGatewayEvent gatewayEvent) throws ArtifactSyn } } + /** + * Check whether the API resource validation is enabled or not. + * + * @return true if enabled, false otherwise + */ + public boolean isAPIResourceValidationEnabled() { + try { + APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration(); + String gatewayResourceCacheEnabled = config.getFirstProperty(APIConstants.GATEWAY_RESOURCE_CACHE_ENABLED); + return Boolean.parseBoolean(gatewayResourceCacheEnabled); + } catch (Exception e) { + log.error("Error occurred while reading Gateway cache configurations. Use default configurations" + e); + } + return true; + } + public void cleanDeployment(String artifactRepositoryPath) { File artifactRepoPath = diff --git a/components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/model/impl/SubscriptionDataStoreImpl.java b/components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/model/impl/SubscriptionDataStoreImpl.java index c84f12cb322f..53f22a2b25bf 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/model/impl/SubscriptionDataStoreImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.keymgt/src/main/java/org/wso2/carbon/apimgt/keymgt/model/impl/SubscriptionDataStoreImpl.java @@ -805,9 +805,6 @@ public void addOrUpdateAPIRevisionWithUrlTemplates(DeployAPIInGatewayEvent event try { API api = apiMap.get(event.getContext() + ":" + event.getVersion()); - if (api != null) { - clearResourceCache(api, event.getTenantDomain()); - } if (APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name().equals(event.getType())) { if (api != null) { removeAPI(api); @@ -818,6 +815,9 @@ public void addOrUpdateAPIRevisionWithUrlTemplates(DeployAPIInGatewayEvent event addOrUpdateAPI(newAPI); } } + if (api != null) { + clearResourceCache(api, event.getTenantDomain()); + } } catch (DataLoadingException e) { log.error("Exception while loading api for " + event.getContext() + " " + event.getVersion(), e); }