use of org.springframework.cache.Cache.ValueWrapper in project cu-kfs by CU-CommunityApps.
the class AttributeValidationHelper method getAttributeDefinitionByName.
protected KimAttribute getAttributeDefinitionByName(String attributeName) {
CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.CACHE_NAME);
Cache cache = cm.getCache(KimAttribute.CACHE_NAME);
// CU Customization (KFSPTS-23531): Build a more specific cache key
String cacheKey = MessageFormat.format(ATTRIBUTE_BY_NAME_CACHE_KEY_PATTERN, attributeName);
ValueWrapper valueWrapper = cache.get(cacheKey);
if (valueWrapper != null) {
return (KimAttribute) valueWrapper.get();
}
Map<String, String> criteria = new HashMap<>();
criteria.put(KRADPropertyConstants.ATTRIBUTE_NAME, attributeName);
List<KimAttribute> attributeImpls = (List<KimAttribute>) getBusinessObjectService().findMatching(KimAttribute.class, criteria);
KimAttribute attribute = null;
if (!attributeImpls.isEmpty()) {
attribute = attributeImpls.get(0);
}
cache.put(cacheKey, attribute);
return attribute;
}
use of org.springframework.cache.Cache.ValueWrapper in project cu-kfs by CU-CommunityApps.
the class AttributeValidationHelper method getAttributeDefinitionById.
protected KimAttribute getAttributeDefinitionById(String id) {
CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.CACHE_NAME);
Cache cache = cm.getCache(KimAttribute.CACHE_NAME);
String cacheKey = "{" + KimAttribute.CACHE_NAME + "}id=" + id;
ValueWrapper valueWrapper = cache.get(cacheKey);
if (valueWrapper != null) {
return (KimAttribute) valueWrapper.get();
}
KimAttribute attribute = getBusinessObjectService().findBySinglePrimaryKey(KimAttribute.class, id);
cache.put(cacheKey, attribute);
return attribute;
}
use of org.springframework.cache.Cache.ValueWrapper in project spring-framework by spring-projects.
the class CaffeineCacheTests method testLoadingCacheGet.
@Test
void testLoadingCacheGet() {
Object value = new Object();
CaffeineCache loadingCache = new CaffeineCache(CACHE_NAME, Caffeine.newBuilder().build(key -> value));
ValueWrapper valueWrapper = loadingCache.get(new Object());
assertThat(valueWrapper).isNotNull();
assertThat(valueWrapper.get()).isEqualTo(value);
}
Aggregations