Skip to content

Package: CacheManager

CacheManager

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18:
19: import java.util.Set;
20:
21: /**
22: * This interface defines basic methods for accessing the shared live object cache.
23: */
24: public interface CacheManager extends Cache {
25:
26: /**
27: * Adds the specified object into the shared session cache.
28: * <p>
29: * If the cache already contains object with the specified identifier (and it is in the same repository context),
30: * it is replaced with the one passed as argument.
31: *
32: * @param identifier Identifier of the specified object
33: * @param entity The object to be added into the cache
34: * @param descriptor Instance descriptor, contains info about repository context(s) and language tags
35: */
36: void add(Object identifier, Object entity, Descriptor descriptor);
37:
38: /**
39: * Gets entity with the specified identifier from the cache.
40: * <p>
41: * The entity is searched for in the context specified by {@code descriptor}. Thus all three conditions - class,
42: * identifier and descriptor must match to return a result.
43: *
44: * @param cls Class of the entity
45: * @param identifier Primary key of the entity
46: * @param descriptor Instance descriptor, contains info about repository context(s) and language tags
47: * @return Entity with the specified primary key or {@code null}
48: */
49: <T> T get(Class<T> cls, Object identifier, Descriptor descriptor);
50:
51: /**
52: * Removes objects with (possibly) inferred attributes from the cache.
53: *
54: * This should be called when changes in the ontology may influence inference results.
55: */
56: void evictInferredObjects();
57:
58: /**
59: * Set the inferred classes for this cache manager.
60: * <p>
61: * Entities from inferred classes are special in that when anything in the ontology changes, they have to be evicted
62: * from the cache, since they are reasoned and their attributes may change.
63: *
64: * @param inferredClasses Set of inferred classes
65: */
66: void setInferredClasses(Set<Class<?>> inferredClasses);
67:
68: /**
69: * Closes the cache.
70: */
71: void close();
72: }