예제 #1
0
  @CheckForNull
  public synchronized byte[] get(@Nonnull String obj, @Nullable Callable<byte[]> valueLoader)
      throws Exception {
    String key = getKey(obj);

    try {
      lock();
      if (!forceUpdate) {
        byte[] cached = getCache(key);

        if (cached != null) {
          log.debug("cache hit for " + obj + " -> " + key);
          return cached;
        }

        log.debug("cache miss for " + obj + " -> " + key);
      } else {
        log.debug("cache force update for " + obj + " -> " + key);
      }

      if (valueLoader != null) {
        byte[] value = valueLoader.call();
        if (value != null) {
          putCache(key, value);
        }
        return value;
      }
    } finally {
      unlock();
    }

    return null;
  }
예제 #2
0
 /**
  * Deletes cache entries that are no longer valid according to the default expiration time period.
  */
 public synchronized void clean() {
   log.info("cache: cleaning");
   try {
     lock();
     deleteCacheEntries(createCleanFilter());
   } catch (IOException e) {
     log.error("Error cleaning cache", e);
   } finally {
     unlock();
   }
 }