use of org.wso2.carbon.caching.impl.CacheImpl in project carbon-apimgt by wso2.
the class APIMgtCacheInvalidationListener method handleCacheInvalidationMessage.
private void handleCacheInvalidationMessage(Map map) {
String cacheManagerName = (String) map.get("cacheManagerName");
String cacheName = (String) map.get("cacheName");
String cacheKey = (String) map.get("cacheKey");
String tenantDomain = (String) map.get("tenantDomain");
int tenantId = (Integer) map.get("tenantId");
String clusterDomain = (String) map.get("clusterDomain");
String nodeId = (String) map.get("nodeId");
if (!DataHolder.getNodeId().equals(nodeId) && cacheInvalidationConfiguration.getDomain().equals(clusterDomain)) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(tenantId);
carbonContext.setTenantDomain(tenantDomain);
CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager(cacheManagerName);
Cache<Object, Object> cache = cacheManager.getCache(cacheName);
Object cacheKeyObject = constructCacheKeyObject(cacheKey);
if (cache instanceof CacheImpl) {
if (CLEAR_ALL_PREFIX.equals(cacheKeyObject)) {
((CacheImpl) cache).removeAllLocal();
} else {
((CacheImpl) cache).removeLocal(cacheKeyObject);
}
}
} catch (ClassNotFoundException e) {
log.error("Error while removing cache Object", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
Aggregations