예제 #1
0
  private Observable<V> fromMemory(User user, K key) {
    UserMemoryCache<K, V> userMemoryCache = userMemoryCaches.get(user);

    if (!userMemoryCache.containsKey(key)) {
      return Observable.empty();
    } else {
      Pair<Long, V> cachedValue = userMemoryCache.get(key);
      long cachedSince = DateUtils.getCurrentTimestamp() - cachedValue.first;

      if (cachedSince < staleThreshold) {
        return Observable.just(userMemoryCache.get(key).second);
      } else {
        // Value has expired
        userMemoryCache.remove(key);
        return Observable.empty();
      }
    }
  }
예제 #2
0
 private void saveToMemory(User user, K key, V value) {
   long currentTimestamp = DateUtils.getCurrentTimestamp();
   getUserCache(user).put(key, value, currentTimestamp);
 }