Exemple #1
0
  /**
   * Put the markup into the cache if cacheKey is not null and the cache does not yet contain the
   * cacheKey. Return the markup stored in the cache if cacheKey is present already.
   *
   * <p>More sophisticated implementations may call a container method to e.g. cache it per
   * container instance.
   *
   * @param locationString If {@code null} then ignore the cache
   * @param container The container this markup is for.
   * @param markup
   * @return markup The markup provided, except if the cacheKey already existed in the cache, then
   *     the markup from the cache is provided.
   */
  protected Markup putIntoCache(
      final String locationString, final MarkupContainer container, Markup markup) {
    if (locationString != null) {
      if (markupCache.containsKey(locationString) == false) {
        // The default cache implementation is a ConcurrentHashMap. Thus neither the key nor
        // the value can be null.
        if (markup == null) {
          markup = Markup.NO_MARKUP;
        }

        markupCache.put(locationString, markup);
      } else {
        // We don't lock the cache while loading a markup. Thus it may
        // happen that the very same markup gets loaded twice (the first
        // markup being loaded, but not yet in the cache, and another
        // request requesting the very same markup). Since markup
        // loading in avg takes less than 100ms, it is not really an
        // issue. For consistency reasons however, we should always use
        // the markup loaded first which is why it gets returned.
        markup = markupCache.get(locationString);
      }
    }
    return markup;
  }