/** * {@inheritDoc} */ @Override public Cache buildCache(String name, Properties properties) throws CacheException { try { CacheManager manager = SingletonEhCacheManagerFactory.getInstance(); if (region2CacheMapping.containsKey(name)) { name = region2CacheMapping.get(name); } net.sf.ehcache.Ehcache cache = manager.getEhcache(name); if (cache == null) { LOGGER.warn("No EhCache configuration for cache named {}" + " found; creating cache with default settings.", name); manager.addCache(name); cache = manager.getEhcache(name); LOGGER.debug("Added EhCache: {}", name); } // use unwrapped caches for performance on ST installations if (CommunoteRuntime.getInstance().getApplicationInformation().isStandalone()) { return new EhCache(cache); } return new ClientDelegateCache(new EhCache(cache)); } catch (net.sf.ehcache.CacheException e) { throw new CacheException(e); } }
public final Cache buildCache(String name, Properties properties) throws CacheException { try { net.sf.ehcache.Ehcache cache = manager.getEhcache(name); if (cache == null) { String s = "Could not find a specific ehcache configuration for cache named [{}]; using defaults."; log.warn(s, name); manager.addCache(name); cache = manager.getEhcache(name); log.debug("started EHCache region: " + name); } return new net.sf.ehcache.hibernate.EhCache(cache); } catch (net.sf.ehcache.CacheException e) { throw new CacheException(e); } }
@AfterReturning("execution (* net.jforum.services.ModerationService.moveTopics(..)) && args(toForumId, log, topicIds)") public void moveTopics(int toForumId, ModerationLog log, int... topicIds) { if (!ArrayUtils.isEmpty(topicIds)) { this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalPosts#" + toForumId)); this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalTopics#" + toForumId)); Cache cache = this.factoryImplementor.getSecondLevelCacheRegion("net.jforum.entities.Forum"); if (cache != null) { cache.remove("net.jforum.entities.Forum#" + toForumId); } Topic topic = (Topic)this.sessionFactory.getCurrentSession().get(Topic.class, topicIds[0]); Forum forum = topic.getForum(); this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalPosts#" + forum.getId())); this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalTopics#" + forum.getId())); Cache cache2 = this.factoryImplementor.getSecondLevelCacheRegion("net.jforum.entities.Forum"); if (cache2 != null) { cache2.remove("net.jforum.entities.Forum#" + forum.getId()); } } }
public void testModerationTopicMoved() throws Exception { this.expectQueryCacheEviction("forumDAO.getTotalPosts#1"); this.expectQueryCacheEviction("forumDAO.getTotalPosts#2"); this.expectQueryCacheEviction("forumDAO.getTotalTopics#1"); this.expectQueryCacheEviction("forumDAO.getTotalTopics#2"); Session session = mock(Session.class); when(sessionFactory.getCurrentSession()).thenReturn(session); Topic topic = new Topic(); topic.getForum().setId(2); when(session.get(Topic.class, 5)).thenReturn(topic); Cache cache = mock(Cache.class); when(sessionFactory.getSecondLevelCacheRegion("net.jforum.entities.Forum")).thenReturn(cache); this.executeTargetMethod(ModerationService.class, "moveTopics", 1, new int[] { 5 }); verify(cache).remove("net.jforum.entities.Forum#1"); verify(cache).remove("net.jforum.entities.Forum#2"); }
@Override public Cache buildCache(String regionName, Properties properties) throws CacheException { if (log.isDebugEnabled()) { log.debug("building cache for regionName=" + regionName + ", with properties: " + properties); } DefaultSimpleCache<Serializable, Object> cache = new DefaultSimpleCache<Serializable, Object>(defaultMaxItems, null); Cache hibCache = new HibernateSimpleCacheAdapter(cache, regionName); return hibCache; }
/** * Second level cache statistics per region * * @param regionName region name * @return SecondLevelCacheStatistics */ public synchronized SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName) { SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) secondLevelCacheStatistics.get(regionName); if (slcs==null) { if (sessionFactory == null) return null; Cache cache = sessionFactory.getSecondLevelCacheRegion(regionName); if (cache==null) return null; slcs = new SecondLevelCacheStatistics(cache); secondLevelCacheStatistics.put(regionName, slcs); } return slcs; }
/** * Configure the cache * * @param regionName the name of the cache region * @param properties configuration settings * @throws CacheException * @noinspection UnusedCatchParameter */ public Cache buildCache(final String regionName, final Properties properties) throws CacheException { int lockTimeoutMillis; try { lockTimeoutMillis = Integer.parseInt(properties.getProperty(PROPERTY_CACHEONIX_LOCK_TIMEOUT, Integer.toString(DEFAULT_LOCK_TIMEOUT_SECS))) * MILLIS_IN_SECOND; } catch (final NumberFormatException e) { lockTimeoutMillis = DEFAULT_LOCK_TIMEOUT_SECS * MILLIS_IN_SECOND; } return new HibernateCacheonixCache(cacheonix, cacheonix.getCache(regionName), lockTimeoutMillis); }
/** * Tests {@link HibernateCacheonixCacheProvider#buildCache(String, Properties)} */ public void testBuildCache() { final Properties properties = new Properties(); final Cache cache = provider.buildCache(TEST_REGION_NAME, properties); assertNotNull(cache); assertEquals(TEST_REGION_NAME, cache.getRegionName()); assertEquals(LONG_ZERO, cache.getElementCountInMemory()); assertEquals(LONG_ZERO, cache.getElementCountOnDisk()); // -1 stands for "not impmeneted" assertEquals(LONG_MINUS_ONE, cache.getSizeInMemory()); assertEquals(DEFAULR_LOC_TIMEOUT_MILLIS, cache.getTimeout()); }
/** * Tests {@link HibernateCacheonixCacheProvider#buildCache(String, Properties)} */ public void testBuildCacheSetsDefaultTimeout() { final Properties properties = new Properties(); properties.setProperty(HibernateCacheonixCacheProvider.PROPERTY_CACHEONIX_LOCK_TIMEOUT, NOT_INTEGER); final Cache cache = provider.buildCache(TEST_REGION_NAME, properties); assertEquals(DEFAULR_LOC_TIMEOUT_MILLIS, cache.getTimeout()); }
@Override public Cache buildCache(String regionName, Properties properties) throws CacheException { if (regionName == null) { regionName = ""; } if (properties == null) { properties = new Properties(); } if (_log.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); Enumeration<Object> enumK = properties.keys(); Collection<Object> enumV = properties.values(); for (int i = 0; i < properties.size(); i++) { sb.append("name="); sb.append(enumK.toString()); sb.append("&value="); sb.append(enumV.toString()); sb.append(";"); } _log.debug("building cache with region: " + regionName + ", properties: " + sb.toString()); } return new TayzGrid(regionName, properties); }
@SuppressWarnings("deprecation") @Override public Cache buildCache(String arg0, Properties arg1) throws CacheException { return new com.solace.caching.hibernate.Cache(arg0, this.m_cache); // ICache cache = null; // // try { // cache = super.loadImplementation(HIBERNATE_CACHE); // // // if // // (!cache.getClass().isInstance(org.hibernate.cache.Cache.class)) // if (!(cache instanceof org.hibernate.cache.Cache)) // throw new ConfigurationException( // String // .format( // "The {} cache registration must implement org.hibernate.cache.Cache", // HIBERNATE_CACHE)); // // cache.setRegionName(arg0); // // m_caches.put(arg0, (org.hibernate.cache.Cache) cache); // } catch (Exception e) { // throw new CacheException("Could not buildCache", e); // } // return (org.hibernate.cache.Cache) m_cache; }
SecondLevelCacheStatistics(Cache cache) { super( cache.getRegionName() ); this.cache = cache; }
public Cache getSecondLevelCacheRegion(String regionName) { synchronized (allCacheRegions) { return (Cache) allCacheRegions.get(regionName); } }
private void clearCacheRegion(Cache cache) { if (cache != null) { cache.clear(); } }
private void expect2ndLevelCacheEviction(final String regionName) { Cache secondLevelCache = mock(Cache.class, regionName); when(sessionFactory.getSecondLevelCacheRegion(regionName)).thenReturn(secondLevelCache); verify(secondLevelCache).clear(); }
/** * @see org.hibernate.cache.CacheProvider#buildCache(java.lang.String, java.util.Properties) */ public Cache buildCache(String regionName, Properties properties) throws CacheException { return new EmptyCache(); }
public Cache buildCache(String regionName, Properties properties) throws CacheException { return this.cacheProvider.buildCache(regionName, properties); }
public Cache buildCache(final String name, final Properties properties) throws CacheException { return new HazelcastCache(instance, name, properties); }
public CacheProvider() { super(); m_caches = new HashMap<String, org.hibernate.cache.Cache>(); }
/** * Constructor. * * @param cacheonix Cacheonix instance. * @param delegate to be used by this implementation of Hibernate's abstraction for caches. * @param lockTimeoutMillis timeout in milliseconds for obtaining a lock. * @noinspection AssignmentToCollectionOrArrayFieldFromParameter */ public HibernateCacheonixCache(final Cacheonix cacheonix, final org.cacheonix.cache.Cache delegate, final int lockTimeoutMillis) { this.cacheonix = cacheonix; this.delegate = delegate; this.lockTimeoutMillis = lockTimeoutMillis; }
/** * Creates a new instance from the cache to wrapped * * @param cacheBackend * the cache to be wrapped */ public ClientDelegateCache(Cache cacheBackend) { this.cacheBackend = cacheBackend; }
/** * Get a named second-level cache region */ public Cache getSecondLevelCacheRegion(String regionName);