Skip to content

Package: Cache

Cache

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.model;
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: */
30: public interface Cache {
31:
32: /**
33: * Checks whether the cache contains data for the given entity.
34: *
35: * @param cls Entity class
36: * @param identifier Instance identifier
37: * @param descriptor Specifies instance context and additional possible information, e.g. language tags
38: * @return {@code boolean} indicating whether the entity is in the cache
39: */
40: boolean contains(Class<?> cls, Object identifier, Descriptor descriptor);
41:
42: /**
43: * Removes the data for the given entity from the cache.
44: *
45: * @param cls Entity class
46: * @param identifier Instance identifier
47: * @param context Context URI, possibly {@code null}, meaning the default context
48: */
49: void evict(Class<?> cls, Object identifier, URI context);
50:
51: /**
52: * Removes the data for entities of the specified class (and its subclasses) from the cache.
53: * <p>
54: * This method removes the entities from all available contexts.
55: *
56: * @param cls entity class
57: */
58: void evict(Class<?> cls);
59:
60: /**
61: * Removes the data for entities of the specified repository context from the cache.
62: *
63: * @param context URI of the context to evict, possibly {@code null}, meaning the default context
64: */
65: void evict(URI context);
66:
67: /**
68: * Clears the cache.
69: */
70: void evictAll();
71: }