CachingWrapperFilter.javaAPI DocApache Lucene 1.92200Mon Feb 20 09:20:04 GMT


public class CachingWrapperFilter extends Filter
Wraps another filter's result and caches it. The caching behavior is like {@link QueryFilter}. The purpose is to allow filters to simply filter, and then wrap with this class to add caching, keeping the two concerns decoupled yet composable.

Fields Summary
private Filter
private transient Map
Constructors Summary
public CachingWrapperFilter(Filter filter)

filter Filter to cache results of

    this.filter = filter;
Methods Summary
public java.util.BitSetbits(org.apache.lucene.index.IndexReader reader)

    if (cache == null) {
      cache = new WeakHashMap();

    synchronized (cache) {  // check cache
      BitSet cached = (BitSet) cache.get(reader);
      if (cached != null) {
        return cached;

    final BitSet bits = filter.bits(reader);

    synchronized (cache) {  // update cache
      cache.put(reader, bits);

    return bits;
public booleanequals(java.lang.Object o)

    if (!(o instanceof CachingWrapperFilter)) return false;
    return this.filter.equals(((CachingWrapperFilter)o).filter);
public inthashCode()

    return filter.hashCode() ^ 0x1117BF25;  
public java.lang.StringtoString()

    return "CachingWrapperFilter("+filter+")";