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