org.springframework.cache.Cache.ValueWrapper Java Examples
The following examples show how to use
org.springframework.cache.Cache.ValueWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CaptchaServiceImpl.java From oauth2-server with MIT License | 6 votes |
@Override public boolean checkCaptchaTimes(CachesEnum cachesEnum, String key) { ValueWrapper valueWrapper = cacheManager.getCache(CachesEnum.CaptchaTimesCache.name()).get(key); if (valueWrapper != null) { int times = Integer.valueOf(String.valueOf(valueWrapper.get())); if (times < captchaMaxTimes) { cacheManager.getCache(CachesEnum.CaptchaTimesCache.name()).put(key, times + 1); return true; } else { log.debug("验证码达到最大尝试次数:" + cachesEnum + "_" + key); removeCaptcha(cachesEnum, key); removeCaptcha(CachesEnum.CaptchaTimesCache, key); return false; } } else { cacheManager.getCache(CachesEnum.CaptchaTimesCache.name()).put(key, 1); return true; } }
Example #2
Source File: CachingTypeConverter.java From conf4j with MIT License | 6 votes |
/** * Converts String to the target type. * This method checks whether the cache contains the converted value, and if not, obtains it from {@link #typeConverter}, * stores conversion result in the cache and provides the result. * * @param type actual type definition. * @param value string representation of the value which is converted to {@code T}. * In case it is {@code null}, converter should return either {@code null} or a value * that is equivalent e.g. an empty list. * @return value converted to type {@code T}. * @param attributes additional meta-data attributes which may be used by converter. It can be {@code null}. * @throws IllegalArgumentException when {@code value} cannot be converted to {@code T}. * @throws NullPointerException when {@code type} is {@code null}. */ @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } }
Example #3
Source File: CustomerService.java From Mastering-Spring-Cloud with MIT License | 6 votes |
public List<Account> findCustomerAccountsFallback(Long id) { ValueWrapper w = cacheManager.getCache("accounts").get(id); if (w != null) { return (List<Account>) w.get(); } else { return new ArrayList<>(); } }
Example #4
Source File: CustomerService.java From Mastering-Spring-Cloud with MIT License | 6 votes |
public List<Account> findCustomerAccountsFallback(Long id) { ValueWrapper w = cacheManager.getCache("accounts").get(id); if (w != null) { return (List<Account>) w.get(); } else { return new ArrayList<>(); } }
Example #5
Source File: SimpleCacheWrapper.java From onetwo with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> T get(String key){ if(!canCache()) return null; ValueWrapper value = cache.get(key); if(value==null) return null; CacheElement ce = (CacheElement)value.get(); if(!ce.isIndate()){ logger.info("clear cache by key: " + ce); return null; } if(logger.isInfoEnabled()){ logger.info("get from cache by key: " + ce); } return (T)ce.getValue(); }
Example #6
Source File: AttributeValidationHelper.java From rice with Educational Community License v2.0 | 6 votes |
protected KimAttribute getAttributeDefinitionById( String id ) { CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.Cache.NAME); Cache cache = cm.getCache(KimAttribute.Cache.NAME); String cacheKey = "id=" + id; ValueWrapper valueWrapper = cache.get( cacheKey ); if ( valueWrapper != null ) { return (KimAttribute) valueWrapper.get(); } KimAttributeBo attributeImpl = KradDataServiceLocator.getDataObjectService().find( KimAttributeBo.class, id ); KimAttribute attribute = KimAttributeBo.to(attributeImpl); cache.put( cacheKey, attribute ); return attribute; }
Example #7
Source File: AttributeValidationHelper.java From rice with Educational Community License v2.0 | 6 votes |
protected KimAttribute getAttributeDefinitionByName( String attributeName ) { CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.Cache.NAME); Cache cache = cm.getCache(KimAttribute.Cache.NAME); String cacheKey = "name=" + attributeName; ValueWrapper valueWrapper = cache.get( cacheKey ); if ( valueWrapper != null ) { return (KimAttribute) valueWrapper.get(); } List<KimAttributeBo> attributeImpls = KradDataServiceLocator.getDataObjectService().findMatching( KimAttributeBo.class, QueryByCriteria.Builder.forAttribute(KRADPropertyConstants.ATTRIBUTE_NAME, attributeName).build()).getResults(); KimAttribute attribute = null; if ( !attributeImpls.isEmpty() ) { attribute = KimAttributeBo.to(attributeImpls.get(0)); } cache.put( cacheKey, attribute ); return attribute; }
Example #8
Source File: CaptchaServiceImpl.java From oauth2-server with MIT License | 5 votes |
@Override public String getCaptcha(CachesEnum cachesEnum, String key) { if (!checkCaptchaTimes(cachesEnum, key)) { return null; } ValueWrapper valueWrapper = cacheManager.getCache(cachesEnum.name()).get(key); if (valueWrapper != null) { return String.valueOf(valueWrapper.get()); } else { return null; } }
Example #9
Source File: ShiroSpringCache.java From xmanager with Apache License 2.0 | 5 votes |
@Override public V get(K key) throws CacheException { if (logger.isTraceEnabled()) { logger.trace("Getting object from cache [" + this.cache.getName() + "] for key [" + key + "]key type:" + key.getClass()); } ValueWrapper valueWrapper = cache.get(key); if (valueWrapper == null) { if (logger.isTraceEnabled()) { logger.trace("Element for [" + key + "] is null."); } return null; } return (V) valueWrapper.get(); }
Example #10
Source File: CustomerService.java From Mastering-Spring-Cloud with MIT License | 5 votes |
public Customer findCustomerWithAccountsFallback(Long customerId) { ValueWrapper w = cacheManager.getCache("customers").get(customerId); if (w != null) { return (Customer) w.get(); } else { return new Customer(); } }
Example #11
Source File: CustomerService.java From Mastering-Spring-Cloud with MIT License | 5 votes |
public Customer findCustomerWithAccountsFallback(Long customerId) { ValueWrapper w = cacheManager.getCache("customers").get(customerId); if (w != null) { return (Customer) w.get(); } else { return new Customer(); } }
Example #12
Source File: WebResourceCache.java From super-cloudops with Apache License 2.0 | 4 votes |
@Override public byte[] get(Object key) { ValueWrapper value = cache.get(key); return isNull(value) ? null : (byte[]) value.get(); }
Example #13
Source File: EhcacheDriver.java From rebuild with GNU General Public License v3.0 | 4 votes |
@Override public String get(String key) { ValueWrapper w = cache().get(key); return w == null ? null : (String) w.get(); }
Example #14
Source File: EhcacheDriver.java From rebuild with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public V getx(String key) { ValueWrapper w = cache().get(key); return w == null ? null : (V) w.get(); }
Example #15
Source File: SpringCacheManager.java From jsets-shiro-spring-boot-starter with Apache License 2.0 | 4 votes |
@Override public V get(K key) throws CacheException { ValueWrapper wrapper = this.delegator.get(key); return wrapper == null ? null : (V) wrapper.get(); }
Example #16
Source File: DefaultDownloadIdCache.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
@Override public DownloadArtifactCache get(final String downloadId) { final ValueWrapper valueWrapper = getCache().get(downloadId); return (valueWrapper == null) ? null : (DownloadArtifactCache) valueWrapper.get(); }