use of net.sf.ehcache.config.CacheConfiguration in project spring-framework by spring-projects.
the class EhCacheSupportTests method doTestEhCacheFactoryBean.
private void doTestEhCacheFactoryBean(boolean useCacheManagerFb) throws Exception {
Cache cache;
EhCacheManagerFactoryBean cacheManagerFb = null;
boolean cacheManagerFbInitialized = false;
try {
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
Class<? extends Ehcache> objectType = cacheFb.getObjectType();
assertTrue(Ehcache.class.isAssignableFrom(objectType));
assertTrue("Singleton property", cacheFb.isSingleton());
if (useCacheManagerFb) {
cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass()));
cacheManagerFb.setCacheManagerName("cache");
cacheManagerFb.afterPropertiesSet();
cacheManagerFbInitialized = true;
cacheFb.setCacheManager(cacheManagerFb.getObject());
}
cacheFb.setCacheName("myCache1");
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
Class<? extends Ehcache> objectType2 = cacheFb.getObjectType();
assertSame(objectType, objectType2);
CacheConfiguration config = cache.getCacheConfiguration();
assertEquals("myCache1", cache.getName());
if (useCacheManagerFb) {
assertEquals("myCache1.maxElements", 300, config.getMaxEntriesLocalHeap());
} else {
assertEquals("myCache1.maxElements", 10000, config.getMaxEntriesLocalHeap());
}
// Cache region is not defined. Should create one with default properties.
cacheFb = new EhCacheFactoryBean();
if (useCacheManagerFb) {
cacheFb.setCacheManager(cacheManagerFb.getObject());
}
cacheFb.setCacheName("undefinedCache");
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache", cache.getName());
assertTrue("default maxElements is correct", config.getMaxEntriesLocalHeap() == 10000);
assertFalse("default eternal is correct", config.isEternal());
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120);
assertTrue("default diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 120);
// overriding the default properties
cacheFb = new EhCacheFactoryBean();
if (useCacheManagerFb) {
cacheFb.setCacheManager(cacheManagerFb.getObject());
}
cacheFb.setBeanName("undefinedCache2");
cacheFb.setMaxEntriesLocalHeap(5);
cacheFb.setTimeToLive(8);
cacheFb.setTimeToIdle(7);
cacheFb.setDiskExpiryThreadIntervalSeconds(10);
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache2", cache.getName());
assertTrue("overridden maxElements is correct", config.getMaxEntriesLocalHeap() == 5);
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 8);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 7);
assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
} finally {
if (cacheManagerFbInitialized) {
cacheManagerFb.destroy();
} else {
CacheManager.getInstance().shutdown();
}
}
}
use of net.sf.ehcache.config.CacheConfiguration in project spring-framework by spring-projects.
the class EhCacheCacheTests method setUp.
@Before
public void setUp() {
cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests").defaultCache(new CacheConfiguration("default", 100)));
nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
cacheManager.addCache(nativeCache);
cache = new EhCacheCache(nativeCache);
}
use of net.sf.ehcache.config.CacheConfiguration in project qi4j-sdk by Qi4j.
the class EhCachePoolMixin method activateService.
@Override
public void activateService() throws Exception {
net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration();
configureEhCache(configuration);
CacheConfiguration cc = createCacheConfiguration("qi4j.ehcache.config.default");
configuration.setDefaultCacheConfiguration(cc);
cacheManager = CacheManager.newInstance(configuration);
}
use of net.sf.ehcache.config.CacheConfiguration in project cas by apereo.
the class EhcacheTicketRegistryConfiguration method ticketRegistry.
@Autowired
@RefreshScope
@Bean
public TicketRegistry ticketRegistry(@Qualifier("ehcacheTicketCacheManager") final CacheManager manager, @Qualifier("ticketCatalog") final TicketCatalog ticketCatalog) {
final EncryptionRandomizedSigningJwtCryptographyProperties crypto = casProperties.getTicket().getRegistry().getEhcache().getCrypto();
final Collection<TicketDefinition> definitions = ticketCatalog.findAll();
definitions.forEach(t -> {
final Ehcache ehcache = buildCache(t);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created Ehcache cache [{}] for [{}]", ehcache.getName(), t);
final CacheConfiguration config = ehcache.getCacheConfiguration();
LOGGER.debug("TicketCache.maxEntriesLocalHeap=[{}]", config.getMaxEntriesLocalHeap());
LOGGER.debug("TicketCache.maxEntriesLocalDisk=[{}]", config.getMaxEntriesLocalDisk());
LOGGER.debug("TicketCache.maxEntriesInCache=[{}]", config.getMaxEntriesInCache());
LOGGER.debug("TicketCache.persistenceConfiguration=[{}]", config.getPersistenceConfiguration().getStrategy());
LOGGER.debug("TicketCache.synchronousWrites=[{}]", config.getPersistenceConfiguration().getSynchronousWrites());
LOGGER.debug("TicketCache.timeToLive=[{}]", config.getTimeToLiveSeconds());
LOGGER.debug("TicketCache.timeToIdle=[{}]", config.getTimeToIdleSeconds());
LOGGER.debug("TicketCache.cacheManager=[{}]", ehcache.getCacheManager().getName());
}
manager.addDecoratedCacheIfAbsent(ehcache);
});
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The following caches are available: [{}]", (Object[]) manager.getCacheNames());
}
return new EhCacheTicketRegistry(ticketCatalog, manager, CoreTicketUtils.newTicketRegistryCipherExecutor(crypto, "ehcache"));
}
use of net.sf.ehcache.config.CacheConfiguration in project cas by apereo.
the class EhCacheTicketRegistry method getTicket.
@Override
public Ticket getTicket(final String ticketIdToGet) {
if (StringUtils.isBlank(ticketIdToGet)) {
return null;
}
final TicketDefinition metadata = this.ticketCatalog.find(ticketIdToGet);
if (metadata == null) {
LOGGER.warn("Ticket [{}] is not registered in the catalog and is unrecognized", ticketIdToGet);
return null;
}
final String ticketId = encodeTicketId(ticketIdToGet);
if (StringUtils.isBlank(ticketId)) {
return null;
}
final Ehcache ehcache = getTicketCacheFor(metadata);
final Element element = ehcache.get(ticketId);
if (element == null) {
LOGGER.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
final Ticket ticket = decodeTicket((Ticket) element.getObjectValue());
final CacheConfiguration config = new CacheConfiguration();
config.setTimeToIdleSeconds(ticket.getExpirationPolicy().getTimeToIdle());
config.setTimeToLiveSeconds(ticket.getExpirationPolicy().getTimeToLive());
if (element.isExpired(config) || ticket.isExpired()) {
ehcache.remove(element);
LOGGER.debug("Ticket [{}] has expired and is now evicted from the cache", ticket.getId());
return null;
}
return ticket;
}
Aggregations