use of org.springframework.cache.annotation.CachePut in project entando-core by entando.
the class ResourceDAO method loadResourceVo.
/**
* Carica un record di risorse in funzione dell'id Risorsa. Questo record รจ
* necessario per l'estrazione della risorse in oggetto tipo
* AbstractResource da parte del ResourceManager.
*
* @param id L'identificativo della risorsa.
* @return Il record della risorsa.
*/
@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'jacms_resource_'.concat(#id)", condition = "null != #id")
public ResourceRecordVO loadResourceVo(String id) {
Connection conn = null;
ResourceRecordVO resourceVo = null;
PreparedStatement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
stat = conn.prepareStatement(LOAD_RESOURCE_VO);
stat.setString(1, id);
res = stat.executeQuery();
if (res.next()) {
resourceVo = new ResourceRecordVO();
resourceVo.setId(id);
resourceVo.setResourceType(res.getString(1));
resourceVo.setDescr(res.getString(2));
resourceVo.setMainGroup(res.getString(3));
resourceVo.setXml(res.getString(4));
resourceVo.setMasterFileName(res.getString(5));
resourceVo.setCreationDate(res.getDate(6));
resourceVo.setLastModified(res.getDate(7));
}
} catch (Throwable t) {
_logger.error("Errore loading resource {}", id, t);
throw new RuntimeException("Errore loading resource" + id, t);
} finally {
closeDaoResources(res, stat, conn);
}
return resourceVo;
}
use of org.springframework.cache.annotation.CachePut in project entando-core by entando.
the class CacheInfoManager method aroundCacheableMethod.
@Around("@annotation(cacheableInfo)")
public Object aroundCacheableMethod(ProceedingJoinPoint pjp, CacheableInfo cacheableInfo) throws Throwable {
Object result = pjp.proceed();
if (cacheableInfo.expiresInMinute() < 0 && (cacheableInfo.groups() == null || cacheableInfo.groups().trim().length() == 0)) {
return result;
}
try {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method targetMethod = methodSignature.getMethod();
Class targetClass = pjp.getTarget().getClass();
Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
Cacheable cacheable = effectiveTargetMethod.getAnnotation(Cacheable.class);
if (null == cacheable) {
CachePut cachePut = effectiveTargetMethod.getAnnotation(CachePut.class);
if (null == cachePut) {
return result;
}
String[] cacheNames = cachePut.value();
Object key = this.evaluateExpression(cachePut.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
for (String cacheName : cacheNames) {
if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
String[] groups = groupsCsv.toString().split(",");
this.putInGroup(cacheName, key.toString(), groups);
}
}
if (cacheableInfo.expiresInMinute() > 0) {
this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
}
}
} else {
String[] cacheNames = cacheable.value();
Object key = this.evaluateExpression(cacheable.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
for (String cacheName : cacheNames) {
if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
String[] groups = groupsCsv.toString().split(",");
this.putInGroup(cacheName, key.toString(), groups);
}
}
if (cacheableInfo.expiresInMinute() > 0) {
this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
}
}
}
} catch (Throwable t) {
logger.error("Error while evaluating cacheableInfo annotation", t);
throw new ApsSystemException("Error while evaluating cacheableInfo annotation", t);
}
return result;
}
use of org.springframework.cache.annotation.CachePut in project entando-core by entando.
the class GuiFragmentManager method getGuiFragmentCodesByWidgetType.
@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'GuiFragment_codesByWidgetType_'.concat(#widgetTypeCode)")
// TODO improve group handling
@CacheableInfo(groups = "'GuiFragment_codesByWidgetTypeGroup'")
public List<String> getGuiFragmentCodesByWidgetType(String widgetTypeCode) throws ApsSystemException {
List<String> codes = null;
try {
FieldSearchFilter filter = new FieldSearchFilter("widgettypecode", widgetTypeCode, false);
filter.setOrder(FieldSearchFilter.Order.ASC);
FieldSearchFilter[] filters = { filter };
codes = this.searchGuiFragments(filters);
} catch (Throwable t) {
logger.error("Error loading fragments code by widget '{}'", widgetTypeCode, t);
throw new ApsSystemException("Error loading fragment codes by widget " + widgetTypeCode, t);
}
return codes;
}
use of org.springframework.cache.annotation.CachePut in project sailfish-mfa by picos-io.
the class PasscodeRequestManagerImpl method requestPasscode.
@CachePut(key = "#requestId")
@Override
public PasscodeRequest requestPasscode(String requestId, int bits, long timeToLive) {
PasscodeRequest passcodeRequest = findById(requestId);
if (passcodeRequest != null) {
return passcodeRequest;
}
passcodeRequest = new PasscodeRequest();
passcodeRequest.setId(requestId);
passcodeRequest.setCode(passcodeGenerator.generate(bits < 4 ? 4 : bits));
passcodeRequest.setCreatedAt(new Date());
passcodeRequest.setExpiredAt(new Date(System.currentTimeMillis() + timeToLive));
return passcodeRequest;
}
use of org.springframework.cache.annotation.CachePut in project entando-core by entando.
the class BaseContentListHelper method getContentsId.
@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "T(com.agiletec.plugins.jacms.aps.system.services.content.helper.BaseContentListHelper).buildCacheKey(#bean, #user)", condition = "#bean.cacheable")
@CacheableInfo(groups = "T(com.agiletec.plugins.jacms.aps.system.JacmsSystemConstants).CONTENTS_ID_CACHE_GROUP_PREFIX.concat(#bean.contentType)", expiresInMinute = 30)
public List<String> getContentsId(IContentListBean bean, UserDetails user) throws Throwable {
this.releaseCache(bean, user);
List<String> contentsId = null;
try {
if (null == bean.getContentType()) {
throw new ApsSystemException("Content type not defined");
}
// this.getAllowedGroups(user);
Collection<String> userGroupCodes = getAllowedGroupCodes(user);
contentsId = this.getContentManager().loadPublicContentsId(bean.getContentType(), bean.getCategories(), bean.getFilters(), userGroupCodes);
} catch (Throwable t) {
_logger.error("Error extracting contents id", t);
throw new ApsSystemException("Error extracting contents id", t);
}
return contentsId;
}
Aggregations