use of org.springframework.cache.annotation.Cacheable in project ocvn by devgateway.
the class ExcelGenerator method getExcelDownload.
/**
* Method that returns a byte array with excel export.
*
* @param filter
* @return
* @throws IOException
*/
@Cacheable
public byte[] getExcelDownload(final YearFilterPagingRequest filter) throws IOException {
PageRequest pageRequest = new PageRequest(filter.getPageNumber(), filter.getPageSize(), Sort.Direction.ASC, "id");
List<Release> releases = mongoTemplate.find(query(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest), Release.class);
ExcelFile releaseExcelFile = new ReleaseExportFile(releases);
Workbook workbook = releaseExcelFile.createWorkbook();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(baos);
byte[] bytes = baos.toByteArray();
return bytes;
}
use of org.springframework.cache.annotation.Cacheable 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.Cacheable in project mica2 by obiba.
the class OpalServiceHelper method getTaxonomies.
// opal root url as key
@Cacheable(value = "opal-taxonomies", key = "#opalJavaClient.newUri().build()")
public Map<String, Taxonomy> getTaxonomies(OpalJavaClient opalJavaClient) {
log.info("Fetching opal taxonomies");
URI uri = opalJavaClient.newUri().segment("system", "conf", "taxonomies").build();
List<Opal.TaxonomyDto> taxonomies = opalJavaClient.getResources(Opal.TaxonomyDto.class, uri, Opal.TaxonomyDto.newBuilder());
ConcurrentMap<String, Taxonomy> taxonomiesList = taxonomies.stream().collect(Collectors.toConcurrentMap(Opal.TaxonomyDto::getName, this::fromDto));
eventBus.post(new OpalTaxonomiesUpdatedEvent(taxonomiesList));
return taxonomiesList;
}
use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.
the class AwsPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions(describeRegionsRequest);
String defaultRegion = awsZoneParameterDefault;
for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) {
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
Filter filter = new Filter();
filter.setName("region-name");
Collection<String> list = new ArrayList<>();
list.add(awsRegion.getRegionName());
filter.setValues(list);
describeAvailabilityZonesRequest.withFilters(filter);
DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
List<AvailabilityZone> tmpAz = new ArrayList<>();
for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : describeAvailabilityZonesResult.getAvailabilityZones()) {
tmpAz.add(availabilityZone(availabilityZone.getZoneName()));
}
regionListMap.put(region(awsRegion.getRegionName()), tmpAz);
DisplayName displayName = regionDisplayNames.get(region(awsRegion.getRegionName()));
if (displayName == null || Strings.isNullOrEmpty(displayName.value())) {
displayNames.put(region(awsRegion.getRegionName()), awsRegion.getRegionName());
} else {
displayNames.put(region(awsRegion.getRegionName()), displayName.value());
}
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.
the class GcpPlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
try {
Set<VmType> types = new HashSet<>();
VmType defaultVmType = null;
CloudRegions regions = regions(cloudCredential, region, filters);
for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
MachineTypeList machineTypeList = compute.machineTypes().list(projectId, availabilityZone.value()).execute();
for (MachineType machineType : machineTypeList.getItems()) {
VmTypeMeta vmTypeMeta = VmTypeMetaBuilder.builder().withCpuAndMemory(machineType.getGuestCpus(), machineType.getMemoryMb().floatValue() / THOUSAND).withMagneticConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisksSizeGb().intValue()).withSsdConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisks()).withMaximumPersistentDisksSizeGb(machineType.getMaximumPersistentDisksSizeGb().toString()).create();
VmType vmType = VmType.vmTypeWithMeta(machineType.getName(), vmTypeMeta, true);
types.add(vmType);
if (machineType.getName().equals(gcpVmDefault)) {
defaultVmType = vmType;
}
}
cloudVmResponses.put(availabilityZone.value(), types);
defaultCloudVmResponses.put(availabilityZone.value(), defaultVmType);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
} catch (Exception e) {
return new CloudVmTypes(new HashMap<>(), new HashMap<>());
}
}
Aggregations