Search in sources :

Example 71 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class IndicadoresMapFindAllInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("colecoesCache");
    Element element = cache.get("indicadoresMap");
    if (element == null) {
        result = invocation.proceed();
        cache.put(new Element("indicadoresMap", result));
    } else {
        result = element.getValue();
        System.out.println("Não foi no banco");
    }
    return result;
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 72 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class PessoaFindInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("pessoasCache");
    Long pessoaId = (Long) invocation.getArguments()[0];
    Element element = cache.get(pessoaId);
    if (element == null) {
        result = invocation.proceed();
        cache.put(new Element(pessoaId, result));
    } else {
        result = element.getValue();
    }
    return result;
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 73 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class TreinamentoSolicitadoFindAllInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("colecoesCache");
    Element element = cache.get("treinamentosSolicitados");
    if (element == null) {
        result = invocation.proceed();
        cache.put(new Element("treinamentosSolicitados", result));
        return result;
    } else {
        return element.getValue();
    }
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 74 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class PessoaUpdateInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache uniqueCache = cacheManager.getCache("pessoasCache");
    Cache collectionsCache = cacheManager.getCache("colecoesCache");
    PessoaDTO pessoa = (PessoaDTO) invocation.getArguments()[0];
    if (pessoa != null) {
        Element uniqueElement = uniqueCache.get(pessoa.getId());
        if (uniqueElement != null) {
            uniqueCache.remove(pessoa.getId());
        }
    }
    Element collectionElement = collectionsCache.get("pessoas");
    if (collectionElement != null) {
        collectionsCache.remove("pessoas");
    }
    result = invocation.proceed();
    return result;
}
Also used : PessoaDTO(com.tomasio.projects.trainning.dto.PessoaDTO) Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 75 with CacheManager

use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.

the class AtividadesEnsinoCacheAdvice method clearChacheTurmas.

private void clearChacheTurmas(String key) throws IOException {
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache1 = cacheManager.getCache("turmas-efetivas-cache");
    cache1.remove(key);
}
Also used : CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3