Package org.hibernate.search.filter

Source Code of org.hibernate.search.filter.MRUFilterCachingStrategy

// $Id: MRUFilterCachingStrategy.java 20861 2010-11-08 10:16:04Z stliu $
package org.hibernate.search.filter;

import java.util.Properties;

import org.apache.lucene.search.Filter;
import org.hibernate.search.Environment;
import org.hibernate.search.backend.configuration.ConfigurationParseHelper;
import org.hibernate.search.util.SoftLimitMRUCache;

/**
* Keep the most recently used Filters in the cache
* The cache is at least as big as <code>hibernate.search.filter.cache_strategy.size</code>
* Above this limit, Filters are kept as soft references
*
* @author Emmanuel Bernard
*/
public class MRUFilterCachingStrategy implements FilterCachingStrategy {
  private static final int DEFAULT_SIZE = 128;
  private SoftLimitMRUCache cache;
  private static final String SIZE = Environment.FILTER_CACHING_STRATEGY + ".size";

  public void initialize(Properties properties) {
    int size = ConfigurationParseHelper.getIntValue( properties, SIZE, DEFAULT_SIZE );
    cache = new SoftLimitMRUCache( size );
  }

  public Filter getCachedFilter(FilterKey key) {
    return (Filter) cache.get( key );
  }

  public void addCachedFilter(FilterKey key, Filter filter) {
    cache.put( key, filter );
  }
}
TOP

Related Classes of org.hibernate.search.filter.MRUFilterCachingStrategy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.