001package com.avaje.ebean.cache;
002
003/**
004 * Represents part of the "L2" server side cache.
005 * <p>
006 * This is used to cache beans or query results (bean collections).
007 * </p>
008 * <p>
009 * There are 2 ServerCache's for each bean type. One is used as the 'bean cache'
010 * which holds beans of a given type. The other is the 'query cache' holding
011 * query results for a given type.
012 * </p>
013 * 
014 * @author rbygrave
015 */
016public interface ServerCache {
017
018  /**
019   * Return the value given the key.
020   */
021  Object get(Object id);
022
023  /**
024   * Put the value in the cache with a given id.
025   */
026  Object put(Object id, Object value);
027
028  /**
029   * Remove a entry from the cache given its id.
030   */
031  Object remove(Object id);
032
033  /**
034   * Clear all entries from the cache.
035   * <p>
036   * NOTE: Be careful using this method in that most of the time application
037   * code should clear BOTH the bean and query caches at the same time. This can
038   * be done via {@link ServerCacheManager#clear(Class)}.
039   * </p>
040   */
041  void clear();
042
043  /**
044   * Return the number of entries in the cache.
045   */
046  int size();
047
048  /**
049   * Return the hit ratio the cache is currently getting.
050   */
051  int getHitRatio();
052
053  /**
054   * Return statistics for the cache.
055   * 
056   * @param reset
057   *          if true the statistics are reset.
058   */
059  ServerCacheStatistics getStatistics(boolean reset);
060}