示例#1
0
  /**
   * Gets an {@link Element} from the Disk Store.
   *
   * @return The element
   */
  public final synchronized Element get(final Object key) {
    try {
      checkActive();

      // Check in the spool.  Remove if present
      Element element;
      synchronized (spoolLock) {
        element = (Element) spool.remove(key);
      }
      if (element != null) {
        element.updateAccessStatistics();
        return element;
      }

      // Check if the element is on disk
      final DiskElement diskElement = (DiskElement) diskElements.get(key);
      if (diskElement == null) {
        // Not on disk
        return null;
      }

      element = loadElementFromDiskElement(diskElement);
      element.updateAccessStatistics();
      return element;
    } catch (Exception exception) {
      LOG.error(
          name
              + "Cache: Could not read disk store element for key "
              + key
              + ". Error was "
              + exception.getMessage(),
          exception);
    }
    return null;
  }
示例#2
0
  /**
   * Gets an item from the cache.
   *
   * <p>The last access time in {@link net.sf.ehcache.Element} is updated.
   *
   * @param key the cache key
   * @return the element, or null if there was no match for the key
   */
  public final Element get(Object key) {

    if (key == null) {
      return null;
    }

    Element element = (Element) map.get(key);

    if (element != null) {
      element.updateAccessStatistics();
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest(cache.getName() + "Cache: " + cache.getName() + "MemoryStore hit for " + key);
      }
    } else if (LOG.isLoggable(Level.FINEST)) {
      LOG.finest(cache.getName() + "Cache: " + cache.getName() + "MemoryStore miss for " + key);
    }

    return element;
  }