Search in sources :

Example 76 with CacheManager

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

the class AtividadesEnsinoCacheAdvice method clearChache.

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

Example 77 with CacheManager

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

the class AtividadesEnsinoCacheAdvice method findTurmaEfetivaMethodInterceptor.

@Around("findTurmaEfetiva()")
public Object findTurmaEfetivaMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("turmas-efetivas-cache");
    Object[] args = joinPoint.getArgs();
    Long turmaId = (Long) args[0];
    Element element = cache.get(turmaId);
    if (element == null) {
        result = joinPoint.proceed();
        cache.put(new Element(turmaId, result));
    } else {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Dados presentes no cache de turmas, 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) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache) Around(org.aspectj.lang.annotation.Around)

Example 78 with CacheManager

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

the class AtividadesEnsinoCacheAdvice method findAllTurmasEfetivasMethodInterceptor.

@Around("findAllTurmasEfetivas()")
public Object findAllTurmasEfetivasMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("turmas-efetivas-cache");
    Object[] args = joinPoint.getArgs();
    if (args[0] == null || args[4] == null) {
        result = joinPoint.proceed();
        return result;
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    String exercicio = df.format((Date) args[0]);
    String gestora = ((Long) args[4]).toString();
    String key = exercicio + "-" + gestora;
    Element element = cache.get(key);
    if (element == null) {
        for (int i = 1; i < 3; i++) {
            if (args[i] != null) {
                result = joinPoint.proceed();
                return result;
            }
        }
        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) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Cache(net.sf.ehcache.Cache) Around(org.aspectj.lang.annotation.Around)

Example 79 with CacheManager

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

the class OrganizationalCacheAdvice method clearChacheOrganizacoes.

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

Example 80 with CacheManager

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

the class OrganizationalCacheAdvice method findPessoaMethodInterceptor.

@Around("findPessoa()")
public Object findPessoaMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = null;
    CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
    Cache cache = cacheManager.getCache("pessoas-cache");
    Object[] args = joinPoint.getArgs();
    Long pessoaId = (Long) args[0];
    Element element = cache.get(pessoaId);
    if (element == null) {
        result = joinPoint.proceed();
        cache.put(new Element(pessoaId, result));
    } else {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Dados presentes no cache de pessoas, 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) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(net.sf.ehcache.Cache) Around(org.aspectj.lang.annotation.Around)

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