Search in sources :

Example 1 with CacheImpl

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();
        }
    }
}
Also used : CacheManager(javax.cache.CacheManager) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) JsonObject(com.google.gson.JsonObject) CacheImpl(org.wso2.carbon.caching.impl.CacheImpl)

Aggregations

JsonObject (com.google.gson.JsonObject)1 CacheManager (javax.cache.CacheManager)1 CacheImpl (org.wso2.carbon.caching.impl.CacheImpl)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1