CachedAttributesService: replaced blocking calls and immediate futures with the true async
This commit is contained in:
parent
c2183be6f5
commit
59d0f36697
@ -113,15 +113,15 @@ public class CachedAttributesService implements AttributesService {
|
||||
validate(entityId, scope);
|
||||
Validator.validateString(attributeKey, "Incorrect attribute key " + attributeKey);
|
||||
|
||||
return cacheExecutor.submit(() -> {
|
||||
AttributeCacheKey attributeCacheKey = new AttributeCacheKey(scope, entityId, attributeKey);
|
||||
TbCacheValueWrapper<AttributeKvEntry> cachedAttributeValue = cache.get(attributeCacheKey);
|
||||
if (cachedAttributeValue != null) {
|
||||
hitCounter.increment();
|
||||
AttributeKvEntry cachedAttributeKvEntry = cachedAttributeValue.get();
|
||||
return Futures.immediateFuture(Optional.ofNullable(cachedAttributeKvEntry));
|
||||
return Optional.ofNullable(cachedAttributeKvEntry);
|
||||
} else {
|
||||
missCounter.increment();
|
||||
return cacheExecutor.submit(() -> {
|
||||
var cacheTransaction = cache.newTransactionForKey(attributeCacheKey);
|
||||
try {
|
||||
Optional<AttributeKvEntry> result = attributesDao.find(tenantId, entityId, scope, attributeKey);
|
||||
@ -133,8 +133,8 @@ public class CachedAttributesService implements AttributesService {
|
||||
log.debug("Could not find attribute from cache: [{}] [{}] [{}]", entityId, scope, attributeKey, e);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -207,7 +207,8 @@ public class CachedAttributesService implements AttributesService {
|
||||
@Override
|
||||
public ListenableFuture<List<AttributeKvEntry>> findAll(TenantId tenantId, EntityId entityId, String scope) {
|
||||
validate(entityId, scope);
|
||||
return Futures.immediateFuture(attributesDao.findAll(tenantId, entityId, scope));
|
||||
// We can`t watch on cache because the keys are unknown.
|
||||
return jpaExecutorService.submit(() -> attributesDao.findAll(tenantId, entityId, scope));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user