private boolean cacheConstraints(List constraintsList,
                             boolean fromPrewarm,
                             MemberName mn) {
      if (CollectionUtils.isEmpty(constraintsList)) {
        return true;
      }
      try {
        tableLock.writeLock().lock();
        int totalSize = constraintsList.stream().mapToInt(constraint -> {
          int size = 0;
          switch (mn) {
          case PRIMARY_KEY_CACHE:
            SQLPrimaryKey pk = (SQLPrimaryKey) constraint;
            String pkName = normalizeIdentifier(pk.getPk_name());
            this.primaryKeyCache.put(pkName, pk);
            size = getObjectSize(SQLPrimaryKey.class, constraint);
            break;
          case FOREIGN_KEY_CACHE:
            SQLForeignKey fk = (SQLForeignKey) constraint;
            String fkName = normalizeIdentifier(fk.getFk_name());
            this.foreignKeyCache.put(fkName, fk);
            size = getObjectSize(SQLForeignKey.class, constraint);
            break;
          case UNIQUE_CONSTRAINT_CACHE:
            SQLUniqueConstraint uc = (SQLUniqueConstraint) constraint;
            String ucName = normalizeIdentifier(uc.getUk_name());
            this.uniqueConstraintCache.put(ucName, uc);
            size = getObjectSize(SQLUniqueConstraint.class, constraint);
            break;
          case NOTNULL_CONSTRAINT_CACHE:
            SQLNotNullConstraint nn = (SQLNotNullConstraint) constraint;
            String nnName = normalizeIdentifier(nn.getNn_name());
            this.notNullConstraintCache.put(nnName, nn);
            size = getObjectSize(SQLNotNullConstraint.class, constraint);
            break;
          case DEFAULT_CONSTRAINT_CACHE:
            SQLDefaultConstraint dc = (SQLDefaultConstraint) constraint;
            String dcName = normalizeIdentifier(dc.getDc_name());
            this.defaultConstraintCache.put(dcName, dc);
            size = getObjectSize(SQLDefaultConstraint.class, constraint);
            break;
          case CHECK_CONSTRAINT_CACHE:
            SQLCheckConstraint cc = (SQLCheckConstraint) constraint;
            String ccName = normalizeIdentifier(cc.getDc_name());
            this.checkConstraintCache.put(ccName, cc);
            size = getObjectSize(SQLCheckConstraint.class, constraint);
            break;
          default:
            LOG.error("Should not reach here");
            break;
          }
          return size;
        }).sum();

        if (!fromPrewarm) {
          setMemberCacheUpdated(mn, true);
        }

        updateMemberSize(mn, totalSize, SizeMode.Snapshot);
        return true;
      } finally {
        tableLock.writeLock().unlock();
      }
    }
Common method to cache constraints
@param constraintsList list of constraints to add to cache
@param fromPrewarm is this method called as part of prewarm phase
@param mn Constraint type
@return memory constraint is handled by cache eviction policy hence this method will always return true
if correct constraint type is provided.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java