示例#1
0
  private void handleCacheUpdate(Object[] args, CacheUpdate cacheUpdate) throws Exception {
    Cache cache = CacheService.getCache(cacheUpdate.cacheName());
    String key =
        generateKey(cacheUpdate.key(), cacheUpdate.keyGenClass(), cacheUpdate.keyGenMethod(), args);

    Object arg = args[cacheUpdate.argNum()];
    Object argUnwrapped = arg;
    if (arg instanceof ValueWrapper) {
      argUnwrapped = ((ValueWrapper) arg).getValue();
    }
    if (argUnwrapped != null || cacheUpdate.cacheNull()) {
      cache.put(key, arg);
    }
  }
示例#2
0
  private Object handleCacheable(Method m, Object[] args, Cacheable cacheable) throws Exception {
    Cache cache = CacheService.getCache(cacheable.cacheName());
    String key =
        generateKey(cacheable.key(), cacheable.keyGenClass(), cacheable.keyGenMethod(), args);
    Object cacheResult = cache.get(key);

    if (cacheResult != null) {
      Object result = ((ValueWrapper) cacheResult).getValue();
      if (result instanceof ValueWrapper) {
        ((ValueWrapper) result).setCacheHit(true);
      }
      return result;
    }

    Object result = m.invoke(obj, args);
    Object resultUnwrapped = result;
    if (result instanceof ValueWrapper) {
      resultUnwrapped = ((ValueWrapper) result).getValue();
    }
    if (resultUnwrapped != null || cacheable.cacheNull()) {
      cache.put(key, result);
    }
    return result;
  }
示例#3
0
 private void handleCacheEvict(Object[] args, CacheEvict cacheEvict) throws Exception {
   Cache cache = CacheService.getCache(cacheEvict.cacheName());
   String key =
       generateKey(cacheEvict.key(), cacheEvict.keyGenClass(), cacheEvict.keyGenMethod(), args);
   cache.evict(key);
 }