public boolean refreshTablesInCache(String catName, String dbName, List<Table> tables) {
    if (isTableCacheDirty.compareAndSet(true, false)) {
      LOG.debug("Skipping table cache update; the table list we have is dirty.");
      return false;
    }
    Map<String, TableWrapper> newCacheForDB = new TreeMap<>();
    for (Table tbl : tables) {
      String tblName = StringUtils.normalizeIdentifier(tbl.getTableName());
      TableWrapper tblWrapper = tableCache.getIfPresent(CacheUtils.buildTableKey(catName, dbName, tblName));
      if (tblWrapper != null) {
        tblWrapper.updateTableObj(tbl, this);
      } else {
        tblWrapper = createTableWrapper(catName, dbName, tblName, tbl);
      }
      newCacheForDB.put(CacheUtils.buildTableKey(catName, dbName, tblName), tblWrapper);
    }
    try {
      cacheLock.writeLock().lock();
      Iterator<Entry<String, TableWrapper>> entryIterator = tableCache.asMap().entrySet().iterator();
      while (entryIterator.hasNext()) {
        String key = entryIterator.next().getKey();
        if (key.startsWith(CacheUtils.buildDbKeyWithDelimiterSuffix(catName, dbName))) {
          entryIterator.remove();
        }
      }
      tableCache.putAll(newCacheForDB);
      return true;
    } finally {
      cacheLock.writeLock().unlock();
    }
  }
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