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();
}
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;
}
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;
}
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();
}
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;
}
Aggregations