Java 类org.hibernate.cache.Cache 实例源码
项目:communote-server
文件:SingletonEhCacheProvider.java
/**
* {@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);
}
}
项目:jeecms6
文件:SpringEhCacheProvider.java
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);
}
}
项目:JForum
文件:CacheEvictionRules.java
@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());
}
}
}
项目:JForum
文件:CacheEvictionRulesTestCase.java
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");
}
项目:Lottery
文件:SpringEhCacheProvider.java
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);
}
}
项目:alfresco-repository
文件:DefaultCacheProvider.java
@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;
}
项目:cacheonix-core
文件:StatisticsImpl.java
/**
* 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;
}
项目:cacheonix-core
文件:HibernateCacheonixCacheProvider.java
/**
* 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);
}
项目:cacheonix-core
文件:HibernateCacheonixCacheProviderTest.java
/**
* 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());
}
项目:cacheonix-core
文件:HibernateCacheonixCacheProviderTest.java
/**
* 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());
}
项目:TayzGrid
文件:TayzGridProvider.java
@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);
}
项目:community-edition-old
文件:DefaultCacheProvider.java
@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;
}
项目:solace.common-java
文件:CacheProvider.java
@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;
}
项目:cacheonix-core
文件:SecondLevelCacheStatistics.java
SecondLevelCacheStatistics(Cache cache) {
super( cache.getRegionName() );
this.cache = cache;
}
项目:cacheonix-core
文件:SessionFactoryImpl.java
public Cache getSecondLevelCacheRegion(String regionName) {
synchronized (allCacheRegions) {
return (Cache) allCacheRegions.get(regionName);
}
}
项目:JForum
文件:CacheEvictionRules.java
private void clearCacheRegion(Cache cache) {
if (cache != null) {
cache.clear();
}
}
项目:JForum
文件:CacheEvictionRulesTestCase.java
private void expect2ndLevelCacheEviction(final String regionName) {
Cache secondLevelCache = mock(Cache.class, regionName);
when(sessionFactory.getSecondLevelCacheRegion(regionName)).thenReturn(secondLevelCache);
verify(secondLevelCache).clear();
}
项目:JForum
文件:EmptyCacheProvider.java
/**
* @see org.hibernate.cache.CacheProvider#buildCache(java.lang.String, java.util.Properties)
*/
public Cache buildCache(String regionName, Properties properties) throws CacheException {
return new EmptyCache();
}
项目:class-guard
文件:LocalCacheProviderProxy.java
public Cache buildCache(String regionName, Properties properties) throws CacheException {
return this.cacheProvider.buildCache(regionName, properties);
}
项目:hazelcast-archive
文件:HazelcastCacheProvider.java
public Cache buildCache(final String name, final Properties properties) throws CacheException {
return new HazelcastCache(instance, name, properties);
}
项目:health-and-care-developer-network
文件:HazelcastCacheProvider.java
public Cache buildCache(final String name, final Properties properties) throws CacheException {
return new HazelcastCache(instance, name, properties);
}
项目:solace.common-java
文件:CacheProvider.java
public CacheProvider() {
super();
m_caches = new HashMap<String, org.hibernate.cache.Cache>();
}
项目:cacheonix-core
文件:HibernateCacheonixCache.java
/**
* 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;
}
项目:communote-server
文件:ClientDelegateCache.java
/**
* Creates a new instance from the cache to wrapped
*
* @param cacheBackend
* the cache to be wrapped
*/
public ClientDelegateCache(Cache cacheBackend) {
this.cacheBackend = cacheBackend;
}
项目:cacheonix-core
文件:SessionFactoryImplementor.java
/**
* Get a named second-level cache region
*/
public Cache getSecondLevelCacheRegion(String regionName);