Search in sources :

Example 36 with CacheManager

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

the class TurmaUpdateInterceptor 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("turmasCache");
    TurmaDTO turma = (TurmaDTO) invocation.getArguments()[0];
    if (turma != null) {
        Element element = cache.get(turma.getId());
        if (element != null) {
            cache.remove(turma.getId());
        }
    }
    result = invocation.proceed();
    return result;
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) TurmaDTO(com.tomasio.projects.trainning.dto.TurmaDTO) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 37 with CacheManager

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

the class AtividadesEnsinoCacheAdvice method findAllTurmasComPendenciasMethodInterceptor.

@Around("findAllComPendendias()")
public Object findAllTurmasComPendenciasMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("turmas-pendencias-cache");
    Object[] args = joinPoint.getArgs();
    if (args[0] == null || args[1] == null) {
        result = joinPoint.proceed();
        return result;
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    String exercicio = df.format((Date) args[0]);
    String organizacao = ((Long) args[1]).toString();
    String key = exercicio + "-" + organizacao;
    Element element = cache.get(key);
    if (element == null) {
        result = joinPoint.proceed();
        cache.put(new Element(key, result));
    } else {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Dados presentes no cache, não foi necessário acesso ao banco de dados");
        result = element.getValue();
    }
    return result;
}
Also used : Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) SimpleDateFormat(java.text.SimpleDateFormat) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache) Around(org.aspectj.lang.annotation.Around)

Example 38 with CacheManager

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

the class AtividadesEnsinoCacheAdvice method clearChachePendencias.

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

Example 39 with CacheManager

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

the class OrganizationalCacheAdvice method clearChachePessoas.

private void clearChachePessoas() throws IOException {
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("pessoas-cache");
    cache.removeAll();
}
Also used : CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache)

Example 40 with CacheManager

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

the class PessoaSearchInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object result;
    String search = (String) invocation.getArguments()[0];
    if (search == null || search.equals("")) {
        CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
        Cache cache = cacheManager.getCache("colecoesCache");
        Element element = cache.get("pessoas");
        if (element == null) {
            result = invocation.proceed();
            cache.put(new Element("pessoas", result));
        } else {
            result = element.getValue();
            System.out.println("Utilizado o cache de pessoas");
        }
    } else {
        result = invocation.proceed();
    }
    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)

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