Search in sources :

Example 66 with CacheConfiguration

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);
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(org.qi4j.api.configuration.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 67 with CacheConfiguration

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;
}
Also used : EnchachePool(io.mycat.cache.impl.EnchachePool) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 68 with CacheConfiguration

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;
}
Also used : lombok.val(lombok.val) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 69 with CacheConfiguration

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);
}
Also used : Element(net.sf.ehcache.Element) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 70 with CacheConfiguration

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());
}
Also used : ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Element(net.sf.ehcache.Element) LoadedResource(org.apereo.portal.utils.cache.resource.LoadedResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) CachedResource(org.apereo.portal.utils.cache.resource.CachedResource) Ehcache(net.sf.ehcache.Ehcache) FileReader(java.io.FileReader) FileSystemResource(org.springframework.core.io.FileSystemResource) CachingResourceLoaderImpl(org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Aggregations

CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)71 Cache (net.sf.ehcache.Cache)26 CacheManager (net.sf.ehcache.CacheManager)16 Ehcache (net.sf.ehcache.Ehcache)14 Configuration (net.sf.ehcache.config.Configuration)14 Element (net.sf.ehcache.Element)9 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)8 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)6 Test (org.junit.Test)6 Resource (org.springframework.core.io.Resource)6 IOException (java.io.IOException)5 Bean (org.springframework.context.annotation.Bean)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)4 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)4 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 FileReader (java.io.FileReader)3 URL (java.net.URL)3 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3