本文整理汇总了Java中org.hibernate.cache.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于org.hibernate.cache包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
/**
* {@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);
}
}
示例2: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
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);
}
}
示例3: args
import org.hibernate.cache.Cache; //导入依赖的package包/类
@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());
}
}
}
示例4: testModerationTopicMoved
import org.hibernate.cache.Cache; //导入依赖的package包/类
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");
}
示例5: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
@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;
}
示例6: getSecondLevelCacheStatistics
import org.hibernate.cache.Cache; //导入依赖的package包/类
/**
* 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;
}
示例7: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
/**
* 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);
}
示例8: testBuildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
/**
* 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());
}
示例9: testBuildCacheSetsDefaultTimeout
import org.hibernate.cache.Cache; //导入依赖的package包/类
/**
* 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());
}
示例10: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
@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);
}
示例11: buildCache
import org.hibernate.cache.Cache; //导入依赖的package包/类
@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;
}
示例12: SecondLevelCacheStatistics
import org.hibernate.cache.Cache; //导入依赖的package包/类
SecondLevelCacheStatistics(Cache cache) {
super( cache.getRegionName() );
this.cache = cache;
}
示例13: getSecondLevelCacheRegion
import org.hibernate.cache.Cache; //导入依赖的package包/类
public Cache getSecondLevelCacheRegion(String regionName) {
synchronized (allCacheRegions) {
return (Cache) allCacheRegions.get(regionName);
}
}
示例14: clearCacheRegion
import org.hibernate.cache.Cache; //导入依赖的package包/类
private void clearCacheRegion(Cache cache) {
if (cache != null) {
cache.clear();
}
}
示例15: expect2ndLevelCacheEviction
import org.hibernate.cache.Cache; //导入依赖的package包/类
private void expect2ndLevelCacheEviction(final String regionName) {
Cache secondLevelCache = mock(Cache.class, regionName);
when(sessionFactory.getSecondLevelCacheRegion(regionName)).thenReturn(secondLevelCache);
verify(secondLevelCache).clear();
}