/**
   * Creates a cached tile layer from the given Layer
   *
   * @param info the layer to cache
   * @param defaults default configuration
   */
  public static GeoServerTileLayerInfoImpl loadOrCreate(
      final LayerInfo layerInfo, final GWCConfig defaults) {
    GeoServerTileLayerInfoImpl info = LegacyTileLayerInfoLoader.load(layerInfo);
    if (info == null) {
      info = create(defaults);
      final ResourceInfo resource = layerInfo.getResource();
      if (resource instanceof FeatureTypeInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultVectorCacheFormats());
      } else if (resource instanceof CoverageInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultCoverageCacheFormats());
      }

      checkAutomaticStyles(layerInfo, info);
    }
    info.setName(tileLayerName(layerInfo));
    info.setId(layerInfo.getId());
    return info;
  }
  /**
   * Creates a default tile layer info based on the global defaults, public only for unit testing
   * purposes.
   */
  public static GeoServerTileLayerInfoImpl create(GWCConfig defaults) {

    GeoServerTileLayerInfoImpl info = new GeoServerTileLayerInfoImpl();

    info.setEnabled(defaults.isCacheLayersByDefault());
    info.setAutoCacheStyles(defaults.isCacheNonDefaultStyles());

    for (String gsetId : defaults.getDefaultCachingGridSetIds()) {
      XMLGridSubset subset = new XMLGridSubset();
      subset.setGridSetName(gsetId);
      info.getGridSubsets().add(subset);
    }

    info.getMimeFormats().addAll(defaults.getDefaultOtherCacheFormats());

    info.setGutter(defaults.getGutter());
    info.setMetaTilingX(defaults.getMetaTilingX());
    info.setMetaTilingY(defaults.getMetaTilingY());
    info.setInMemoryCached(true);

    return info;
  }