/**
   * Get a WMSTile or an empty lockable WMSTile. Used to avoid index queries for the same
   * information.
   *
   * @param query Search url params to store as String.
   * @param colourmode colourmode as String
   * @param pointType data resolution as PointType
   * @return WMSTile that can be in varying states: - being filled when !getCached() and
   *     isCacheable() and is locked - will not be filled when !isCacheable() - ready to use when
   *     getCached()
   */
  public WMSTile get(String query, String colourmode, PointType pointType) {
    String key = getKey(query, colourmode, pointType);
    WMSTile obj = null;
    synchronized (getLock) {
      obj = cache.get(key);

      if (obj != null && obj.getCreated() + maxAge < System.currentTimeMillis()) {
        cache.remove(key);
        obj = null;
      }

      if (obj == null) {
        obj = new WMSTile();
        cache.put(key, obj);
      }
    }

    if (obj != null) {
      obj.lastUse = System.currentTimeMillis();
    }

    return obj;
  }
  /**
   * Store search params and return key.
   *
   * @param q Search url params to store as String.
   * @param colourMode to store as String
   * @param pointType resolution of data to store as PointType
   * @param wco data to store as WMSTile
   * @return true when successfully added to the cache. WMSCache must be enabled, not full. wco must
   *     be not too large and not cause the cache to exceed max size when added.
   */
  public boolean put(String q, String colourMode, PointType pointType, WMSTile wco) {
    if (isFull() || !isEnabled()) {
      return false;
    }

    wco.updateSize();

    synchronized (counterLock) {
      if (cacheSize + wco.getSize() > maxCacheSize) {
        return false;
      }
      cache.put(getKey(q, colourMode, pointType), wco);
      cacheSize += wco.getSize();
      logger.debug("new cache size: " + cacheSize);
      updateTriggerCleanSize();
      if (cacheSize > triggerCleanSize) {
        counter.countDown();
      }
    }

    wco.setCached(true);

    return true;
  }