2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.search;
20
import org.apache.solr.core.SolrInfoMBean;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
import java.io.IOException;
29
* Primary API for dealing with Solr's internal caches.
31
* @version $Id: SolrCache.java 890250 2009-12-14 09:42:00Z shalin $
33
public interface SolrCache<K,V> extends SolrInfoMBean {
34
public final static Logger log = LoggerFactory.getLogger(SolrCache.class);
38
* The initialization routine. Instance specific arguments are passed in
39
* the <code>args</code> map.
41
* The persistence object will exist across different lifetimes of similar caches.
42
* For example, all filter caches will share the same persistence object, sometimes
43
* at the same time (it must be threadsafe). If null is passed, then the cache
44
* implementation should create and return a new persistence object. If not null,
45
* the passed in object should be returned again.
47
* Since it will exist across the lifetime of many caches, care should be taken to
48
* not reference any particular cache instance and prevent it from being
49
* garbage collected (no using inner classes unless they are static).
51
* The persistence object is designed to be used as a way for statistics
52
* to accumulate across all instances of the same type of cache, however the
53
* object may be of any type desired by the cache implementation.
55
* The {@link CacheRegenerator} is what the cache uses during auto-warming to
56
* renenerate an item in the new cache from an entry in the old cache.
59
public Object init(Map args, Object persistence, CacheRegenerator regenerator);
60
// I don't think we need a factory for faster creation given that these
61
// will be associated with slow-to-create SolrIndexSearchers.
62
// change to NamedList when other plugins do?
65
* Name the Cache can be referenced with by SolrRequestHandlers.
67
* This method must return the identifier that the Cache instance
68
* expects SolrRequestHandlers to use when requesting access to it
69
* from the SolrIndexSearcher. It is <strong>strongly</strong>
70
* recommended that this method return the value of the "name"
71
* parameter from the init args.
78
// Should SolrCache just extend the java.util.Map interface?
79
// Following the conventions of the java.util.Map interface in any case.
81
/** :TODO: copy from Map */
84
/** :TODO: copy from Map */
85
public V put(K key, V value);
87
/** :TODO: copy from Map */
90
/** :TODO: copy from Map */
94
* Enumeration of possible States for cache instances.
95
* :TODO: only state that seems to ever be set is LIVE ?
109
* Set different cache states.
110
* The state a cache is in can have an effect on how statistics are kept.
111
* The cache user (SolrIndexSearcher) will take care of switching
114
public void setState(State state);
117
* Returns the last State set on this instance
121
public State getState();
125
* Warm this cache associated with <code>searcher</code> using the <code>old</code>
126
* cache object. <code>this</code> and <code>old</code> will have the same concrete type.
128
void warm(SolrIndexSearcher searcher, SolrCache<K,V> old) throws IOException;
129
// Q: an alternative to passing the searcher here would be to pass it in
130
// init and have the cache implementation save it.
133
/** Frees any non-memory resources */