@Test public void testGetCache() throws Exception { // Create on missing IntrabandPortalCacheManager<String, String> intraBandPortalCacheManager = new IntrabandPortalCacheManager<String, String>(_mockRegistrationReference); Map<String, PortalCache<?, ?>> portalCaches = getPortalCaches(intraBandPortalCacheManager); Assert.assertTrue(portalCaches.isEmpty()); String portalCacheName = "portalCacheName"; PortalCache<?, ?> portalCache = intraBandPortalCacheManager.getCache(portalCacheName); Assert.assertNotNull(portalCache); Assert.assertEquals(portalCacheName, portalCache.getName()); Assert.assertEquals(1, portalCaches.size()); Assert.assertSame(portalCache, portalCaches.get(portalCacheName)); // Get existing PortalCache<?, ?> portalCache2 = intraBandPortalCacheManager.getCache(portalCacheName); Assert.assertNotNull(portalCache2); Assert.assertEquals(portalCacheName, portalCache2.getName()); Assert.assertEquals(1, portalCaches.size()); Assert.assertSame(portalCache, portalCache2); }
public void putResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, Object result) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive() || (result == null)) { return; } result = ((BaseModel<?>) result).toCacheModel(); if (_localCacheAvailable) { Map<Serializable, Object> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.put(localCacheKey, result); } PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); portalCache.put(cacheKey, result); }
public void clearCache() { clearLocalCache(); for (PortalCache portalCache : _portalCaches.values()) { portalCache.removeAll(); } }
public void clearCache(String className) { clearLocalCache(); PortalCache portalCache = _getPortalCache(className, false); if (portalCache != null) { portalCache.removeAll(); } }
@Override public void clearCache(Class<?> clazz) { clearLocalCache(); PortalCache<?, ?> portalCache = _getPortalCache(clazz, true); if (portalCache != null) { portalCache.removeAll(); } }
@Override public void notifyRemoveAll(PortalCache<K, V> portalCache) throws PortalCacheException { if (!_replicateRemovals) { return; } PortalCacheManager<K, V> portalCacheManager = portalCache.getPortalCacheManager(); PortalCacheClusterEvent portalCacheClusterEvent = new PortalCacheClusterEvent( portalCacheManager.getName(), portalCache.getName(), null, PortalCacheClusterEventType.REMOVE_ALL); PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent); }
@Override public void notifyEntryRemoved(PortalCache<K, V> portalCache, K key, V value, int timeToLive) throws PortalCacheException { if (!_replicateRemovals) { return; } PortalCacheManager<K, V> portalCacheManager = portalCache.getPortalCacheManager(); PortalCacheClusterEvent portalCacheClusterEvent = new PortalCacheClusterEvent( portalCacheManager.getName(), portalCache.getName(), key, PortalCacheClusterEventType.REMOVE); PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent); }
@Override public Serializable getResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { return null; } Serializable result = null; Map<Serializable, Serializable> localCache = null; Serializable localCacheKey = null; if (_LOCAL_CACHE_AVAILABLE) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } if (result == null) { PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { result = StringPool.BLANK; } if (_LOCAL_CACHE_AVAILABLE) { localCache.put(localCacheKey, result); } } return _toEntityModel(result); }
public void removeResult(boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { return; } if (_localCacheAvailable) { Map<Serializable, Object> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.remove(localCacheKey); } PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); portalCache.remove(cacheKey); }
@Override public void notifyEntryPut(PortalCache<K, V> portalCache, K key, V value, int timeToLive) throws PortalCacheException { if (!_replicatePuts) { return; } PortalCacheManager<K, V> portalCacheManager = portalCache.getPortalCacheManager(); PortalCacheClusterEvent portalCacheClusterEvent = new PortalCacheClusterEvent( portalCacheManager.getName(), portalCache.getName(), key, PortalCacheClusterEventType.PUT); if (_replicatePutsViaCopy) { portalCacheClusterEvent.setElementValue(value); portalCacheClusterEvent.setTimeToLive(timeToLive); } PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent); }
@Override public void putResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, Serializable result, boolean quiet) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive() || (result == null)) { return; } result = ((BaseModel<?>) result).toCacheModel(); if (_LOCAL_CACHE_AVAILABLE) { Map<Serializable, Serializable> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.put(localCacheKey, result); } PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); if (quiet) { PortalCacheHelperUtil.putWithoutReplicator(portalCache, cacheKey, result); } else { portalCache.put(cacheKey, result); } }
/** @deprecated */ public void put(PortalCache portalCache, String key, Serializable value, int timeToLive) { portalCache.put(key, value, timeToLive); }
/** @deprecated */ public void put(PortalCache portalCache, String key, Serializable value) { portalCache.put(key, value); }
/** @deprecated */ public void put(PortalCache portalCache, String key, Object value, int timeToLive) { portalCache.put(key, value, timeToLive); }
/** @deprecated */ public void put(PortalCache portalCache, String key, Object value) { portalCache.put(key, value); }
public Object get(String name, String key) { PortalCache portalCache = getCache(name); return portalCache.get(key); }
protected void clearFinderCache() { PortalCache<String, SocialActivityCounter> portalCache = MultiVMPoolUtil.getPortalCache(SocialActivityCounterFinder.class.getName()); portalCache.removeAll(); }
/** @deprecated */ public void remove(PortalCache portalCache, String key) { portalCache.remove(key); }
public Object loadResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, SessionFactory sessionFactory) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { Session session = null; try { session = sessionFactory.openSession(); return session.load(clazz, primaryKey); } finally { sessionFactory.closeSession(session); } } Object result = null; Map<Serializable, Object> localCache = null; Serializable localCacheKey = null; if (_localCacheAvailable) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } Object loadResult = null; if (result == null) { PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { if (_log.isDebugEnabled()) { _log.debug("Load " + clazz + " " + primaryKey + " from session"); } Session session = null; try { session = sessionFactory.openSession(); loadResult = session.load(clazz, primaryKey); } finally { if (loadResult == null) { result = StringPool.BLANK; } else { result = ((BaseModel<?>) loadResult).toCacheModel(); } portalCache.put(cacheKey, result); sessionFactory.closeSession(session); } } if (_localCacheAvailable) { localCache.put(localCacheKey, result); } } if (loadResult != null) { return loadResult; } else { return _toEntityModel(result); } }
@Override public Serializable loadResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, SessionFactory sessionFactory) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { Session session = null; try { session = sessionFactory.openSession(); return (Serializable) session.load(clazz, primaryKey); } finally { sessionFactory.closeSession(session); } } Serializable result = null; Map<Serializable, Serializable> localCache = null; Serializable localCacheKey = null; if (_LOCAL_CACHE_AVAILABLE) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } Serializable loadResult = null; if (result == null) { PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { if (_log.isDebugEnabled()) { _log.debug("Load " + clazz + " " + primaryKey + " from session"); } Session session = null; try { session = sessionFactory.openSession(); loadResult = (Serializable) session.load(clazz, primaryKey); } finally { if (loadResult == null) { result = StringPool.BLANK; } else { result = ((BaseModel<?>) loadResult).toCacheModel(); } PortalCacheHelperUtil.putWithoutReplicator(portalCache, cacheKey, result); sessionFactory.closeSession(session); } } if (_LOCAL_CACHE_AVAILABLE) { localCache.put(localCacheKey, result); } } if (loadResult != null) { return loadResult; } return _toEntityModel(result); }
public void put(String name, String key, Object value) { PortalCache portalCache = getCache(name); portalCache.put(key, value); }
public void put(String name, String key, Serializable value) { PortalCache portalCache = getCache(name); portalCache.put(key, value); }
public void clear(String name) { PortalCache portalCache = getCache(name); portalCache.removeAll(); }
public void remove(String name, String key) { PortalCache portalCache = getCache(name); portalCache.remove(key); }
/** @deprecated */ public Object get(PortalCache portalCache, String key) { return portalCache.get(key); }