use of net.sf.ehcache.config.CacheConfiguration in project qi4j-sdk by Qi4j.
the class EhCachePoolMixin method activateCache.
@Override
public void activateCache() 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 = new CacheManager(configuration);
}
use of net.sf.ehcache.config.CacheConfiguration in project Mycat-Server by MyCATApache.
the class TestCachePoolPerformance method createEnCachePool.
public static CachePool createEnCachePool() {
CacheConfiguration cacheConf = new CacheConfiguration();
cacheConf.setName("testcache");
cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES).timeToIdleSeconds(3600);
Cache cache = new Cache(cacheConf);
CacheManager.create().addCache(cache);
EnchachePool enCachePool = new EnchachePool(cacheConf.getName(), cache, 400 * 10000);
return enCachePool;
}
use of net.sf.ehcache.config.CacheConfiguration in project cas by apereo.
the class EhCacheTicketRegistry method getTicket.
@Override
public Ticket getTicket(final String ticketIdToGet, final Predicate<Ticket> predicate) {
if (StringUtils.isBlank(ticketIdToGet)) {
return null;
}
val metadata = this.ticketCatalog.find(ticketIdToGet);
if (metadata == null) {
LOGGER.warn("Ticket [{}] is not registered in the catalog and is unrecognized", ticketIdToGet);
return null;
}
val ticketId = encodeTicketId(ticketIdToGet);
if (StringUtils.isBlank(ticketId)) {
return null;
}
val ehcache = getTicketCacheFor(metadata);
val element = ehcache.get(ticketId);
if (element == null) {
LOGGER.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
val ticket = decodeTicket((Ticket) element.getObjectValue());
val config = new CacheConfiguration();
val expirationPolicy = ticket.getExpirationPolicy();
config.setTimeToIdleSeconds(expirationPolicy.getTimeToIdle());
config.setTimeToLiveSeconds(expirationPolicy.getTimeToLive());
if (!element.isExpired(config) && predicate.test(ticket)) {
return ticket;
}
return null;
}
use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.
the class PortletCacheControlServiceImpl method cacheElement.
/**
* Construct an appropriate Cache {@link Element} for the cacheKey and data. The element's ttl
* will be set depending on whether expiration or validation method is indicated from the
* CacheControl and the cache's configuration.
*/
protected void cacheElement(Ehcache cache, Serializable cacheKey, CachedPortletResultHolder<?> data, CacheControl cacheControl) {
// using validation method, ignore expirationTime and defer to cache configuration
if (cacheControl.getETag() != null) {
final Element element = new Element(cacheKey, data);
cache.put(element);
return;
}
// using expiration method, -1 for CacheControl#expirationTime means "forever" (e.g. ignore
// and defer to cache configuration)
final int expirationTime = cacheControl.getExpirationTime();
if (expirationTime == -1) {
final Element element = new Element(cacheKey, data);
cache.put(element);
return;
}
// using expiration method with a positive expiration, set that value as the element's TTL
// if it is lower than the configured cache TTL
final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
final Element element = new Element(cacheKey, data);
final long cacheTTL = cacheConfiguration.getTimeToLiveSeconds();
if (expirationTime < cacheTTL) {
element.setTimeToLive(expirationTime);
}
cache.put(element);
}
use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.
the class CachingResourceLoaderImplTest method testUncachedLoad.
@Test
public void testUncachedLoad() throws Exception {
final Resource doc1Resouce = new FileSystemResource(doc1);
final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
final Ehcache cache = createMock(Ehcache.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(cache.getInternalContext()).andReturn(null).anyTimes();
expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
expect(cache.get(doc1Resouce)).andReturn(null);
expect(cache.getQuiet(doc1Resouce)).andReturn(null);
cache.put(anyObject(Element.class));
expectLastCall();
replay(cache, elementsProvider);
loader.setResourceCache(cache);
loader.setResourcesElementsProvider(elementsProvider);
final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
verify(cache, elementsProvider);
assertNotNull(cachedResource1);
final String expected = IOUtils.toString(new FileReader(doc1));
assertEquals(expected, cachedResource1.getCachedResource());
}
Aggregations