Skip to content

Package: Cache

Cache

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 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;
19:
20: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
21:
22: import java.net.URI;
23:
24: /**
25: * Interface used to interact with the second-level cache.
26: * <p>
27: * If a cache is not in use, the methods of this interface have no effect, except for contains, which
28: * returns false.
29: * <p>
30: * Taken from JPA 2.
31: */
32: public interface Cache {
33:
34: /**
35: * Checks whether the cache contains data for the given entity.
36: *
37: * @param cls Entity class
38: * @param identifier Instance identifier
39: * @param descriptor Specifies instance context and additional possible information, e.g. language tags
40: * @return {@code boolean} indicating whether the entity is in the cache
41: */
42: boolean contains(Class<?> cls, Object identifier, Descriptor descriptor);
43:
44: /**
45: * Removes the data for the given entity from the cache.
46: *
47: * @param cls Entity class
48: * @param identifier Instance identifier
49: * @param context Context URI, possibly {@code null}, meaning the default context
50: */
51: void evict(Class<?> cls, Object identifier, URI context);
52:
53: /**
54: * Removes the data for entities of the specified class (and its subclasses) from the cache.
55: * <p>
56: * This method removes the entities from all available contexts.
57: *
58: * @param cls entity class
59: */
60: void evict(Class<?> cls);
61:
62: /**
63: * Removes the data for entities of the specified repository context from the cache.
64: *
65: * @param context URI of the context to evict, possibly {@code null}, meaning the default context
66: */
67: void evict(URI context);
68:
69: /**
70: * Clears the cache.
71: */
72: void evictAll();
73: }