Skip to content

Package: CacheManager

CacheManager

Coverage

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