public List<SQLForeignKey> listCachedForeignKeys(String catName, String foreignDbName, String foreignTblName,
                                                   String parentDbName, String parentTblName) {
    List<SQLForeignKey> keys = new ArrayList<>();
    try {
      cacheLock.readLock().lock();
      TableWrapper tblWrapper = tableCache.getIfPresent(CacheUtils.buildTableKey(catName, foreignDbName, foreignTblName));
      if ((tblWrapper != null) && tblWrapper.isConstraintsValid()) {
        keys = tblWrapper.getForeignKeys();
      }
    } finally {
      cacheLock.readLock().unlock();
    }

    // filter out required foreign keys based on parent db/tbl name
    if (!StringUtils.isEmpty(parentTblName) && !StringUtils.isEmpty(parentDbName)) {
      return keys
        .stream()
        .filter(key -> parentDbName.equalsIgnoreCase(key.getPktable_db())
          && parentTblName.equalsIgnoreCase(key.getPktable_name()))
        .collect(Collectors.toList());
    }
    return keys;
  }
Replaces the old db object with the new one. This will add the new database to cache if it does
not exist.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java