Code example for Cache

Methods: getIfPresent

    if (!sessionToken.isPresent()) {
      return Optional.absent();
    // Check the cache 
    Optional<UserDto> clientUser = Optional.fromNullable(sessionTokenCache.getIfPresent(sessionToken.get()));
    // TODO What is a better way of implementing this? 
    if (clientUser.isPresent()) {
      // Ensure we refresh the cache on a check to maintain the session timeout 
      sessionTokenCache.put(clientUser.get().getSessionToken(), clientUser.get());
    return clientUser;
   * @param sessionToken The session token to use to locate the user 
   * @param clientUser   The client user to cache 
Experience pair programming with AI  Get Codota for Java